Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Having trouble with template rendering #55

Open
rogerjin12 opened this issue Jan 26, 2017 · 0 comments
Open

Having trouble with template rendering #55

rogerjin12 opened this issue Jan 26, 2017 · 0 comments

Comments

@rogerjin12
Copy link

I am fairly new to Meteor and am have been trouble getting Meteor-SSR to work for a blog example app I am working on.

With the code shown below, when I do a browser reload of /blog, all that gets output is hi instead of the blog posts. What I want is a list of blog posts (and then also things like meta tags).

Here's the application code:

// main.js
Router.route('/', function() {
  this.render("Home")
});

if (Meteor.isServer) {
  Router.route('/blog', function() {    
    var posts = [{slug: 'hi', title: "yo"}, {slug: 'hi', title: "yo"}];

    SSR.compileTemplate('blog', Assets.getText('blog.html'));

    let html = SSR.render('blog', {posts: posts});
    this.response.end(html);
  }, {where: 'server'});
}

if (Meteor.isClient) {
  Router.route('/blog', function() {    
    var posts = [{slug: 'hi', title: "yo"}, {slug: 'hi', title: "yo"}];
    
    this.render('Blog', {data: {posts: response.data.data}});
  });
}

Here's the main template:

// main.html
<head>
  <title>cms-powered-blog</title>
</head>
<body>
</body>

<template name="home">
  <a href="/blog">Go to blog</a>
</template>

<template name="blog">
<h2>Blog Posts</h2>
{{#each posts}}
  <a href="/blog/{{slug}}">{{title}}</a>
  <br>
{{/each}}
</template>

Here's the template for server-side rendering:

// private/blog.html
<head>
  <title>cms-powered-blog</title>
</head>
<body>hi</body>

<template name="blog">
<h2>Blog Posts</h2>
{{#each posts}}
  <a href="/blog/{{slug}}">{{title}}</a>
  <br>
{{/each}}
</template>

I've also posted my question here:
https://stackoverflow.com/questions/41882213/meteor-ssr-blaze-template-rendering-not-working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant