Accessing nested objects in a Meteor application using Blaze and Spacebars Accessing nested objects in a Meteor application using Blaze and Spacebars mongodb mongodb

Accessing nested objects in a Meteor application using Blaze and Spacebars


This is happening because {{comment}} is an object itself. Here's some sample code to get the message property showing:

<template name="post_detail">  <div class="container">  <p>Title: {{title}}</p>  <h5>Description: </h5>  <p>{{description}}</p>  <h4>Comments</h4>   <ul>    {{#each comment in comments}}    <li>{{comment.comments}} | {{emailForUser comment.user}}</li>    {{/each}}      </ul>    {{>comments}}</div></template>

If you want to get the user's email address as per my example above, you'll want to add a template helper:

Template.post_detail.helpers({    emailForUser( id ) {        var user = Meteor.users.findOne({_id: id});        if( user ) {            return user.emails[0].address;        }    }});