Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Simple data reflection in meteor's template

Simple data reflection in meteor's template


I'm newbie at meteor and have one big misunderstanding how templates working with data reflection. For example I have some data in database like this:

{name: {firstName: "foo",
lastName: "bar"},
father: "buz"}

the way I can reflect it is really scary for me. I can reflect it only like this:


var Products = new Meteor.Collection("Products");

if (Meteor.isClient) {
  Template.DataTry.dataTryArr = function(){
     return DataTry.find({father: "buz"});



It is working and reflecting. But I can not understand that {{#each}} and why i need dataTryArr in all! is is not working w/o dataTryArr, {{#if dataTryArr}}, Template.DataTry = function(){...} etc. in all it is not working any way w/o {{#each}} (what to iterate there?!)

Please, help me to understand how to reflect simple data like this way


Thanks in advance

Problem courtesy of: Pruntoff


You must use either {{#each}} or {{#with}} block helpers to iterate over the values returned from the template helpers.

If your Template Helper Returns bunch of data from the collection, you might need the {{#each}} iterator, in order to render the returned values in DOM. And if the template helper returns single object, in that case {{#with}} block can be used.

And you have suggested this:


This will not work in any way, you shuold enclose the


within {{#each}} block if the Template.DataTry.dataTryArr() returns array of objects.

In simple words, {{#each dataTryArr}} will call the dataTryArr method and will iterate over the values returned.

Solution courtesy of: sohel khalifa


View additional discussion.

This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Simple data reflection in meteor's template


Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription