Iron router data option, each loop?

In a helper I could do something like

Template.example.helpers posts: -> Collection.find()

and then just use {{#each posts}} to loop through each document. Is there a way to do this using the data: option in a route with iron router?

1 Like

You can use Iron Router’s data method to set the templates data context. You can access this by using {{each this}} if you return a single collection.

Otherwise returning an object with return {posts: Posts.find(...) } would give you the same API using {{each posts}} (I think at least).

However after writing thousands of lines of Meteor production code… I’m back to fetching data in the template level. Specifically the topmost parent, which is usually the page template (Using Template.subscribe). This solves a lot of headache with the router re-running and makes things cleaner (IMHO).

3 Likes