Skip to content

Having trouble with template rendering #55

@rogerjin12

Description

@rogerjin12

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions