Example:
I am writing a Meteor app that deals with a list of blog posts. All blog posts are stored in a collection called 'Posts'. I use Iron Router for routing.
I want to show the user a list of all the posts created by a particular author. This list will be displayed using Spacebars. Therefore, I need to provide the data to the template.
Problem:
As far as I know, there are two ways to do this:
- Using template helpers
- Using the 'data'-property of my route
Option 1 example:
Template.postList.helpers({
postsToDisplay: function(){
return Posts.find({author: 'someAuthor'});
}
})
Option 2 example:
//Inside my route
data: function(){
return {postsToDisplay: Posts.find({author: 'someAuthor'})};
}
Question
Are there any significant differences between those two methods? Is there a reason to prefer one over the other? Does one deliver better performance?
Thank you very much for your answers!