Iron rendering template with data -> no data returned


#1
Router.route('/katalog', function () {
  this.render('katalog', {
      data: function() { return Products.find(); }       });
});

=> no rendered data in template:

 <template>
 {{#each products}}
 		<div>
 			<h3>{{name}}</h3>
 			{{price}}
 		</div>
 {{/each}}
 </template>

though in console Products.find() show correct data:

Products.find().fetch()
[Object_id: "bSrJqp3gtGuRQ94BP
name: …name…
price: 1798.5
proto:
Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]

and if i add helper

Template.katalog.helpers({
  products(){
     return Products.find();
  }
});

it shows data,
why is this happening?


#2

Not sure if you figured this out, but you need the helper, so that your each has a data context.

Also, data should really be fetched at the template level, not the router level.


#3

but this is should work?
http://iron-meteor.github.io/iron-router/#rendering-templates-with-data