Reputation: 290
I'm using fixtureadapter and have the following models:
user (id, name, hasMany:poll)
poll (id, question, belongsTo:user, hasMany:item)
item (id, text, votes, belongsTo:poll)
What is the best way to have something like this in handlebars file:
{{poll user=1}} or {{poll id=32}}
and that would render (the latest poll of user or) the poll with question text + items.
"What is the best js framework?"
- ember.js
- angular.js
- other
"question by: username"
Upvotes: 1
Views: 1508
Reputation: 93
You can use the 'render' helper in ember and pass a model to it.
{{render 'pollWithQuestions' poll}}
This would render a template, controller and view named 'PollWithQuestions' and use the model of poll that you passed in.
I would have the PollWithQuestionsController
handle the logic for whether it should show the latest poll for a user if that is what you've passed instead of an actual poll. You should never handle that kind of logic in your template and that is the primary reason that handlebars does not support it.
For reference: http://emberjs.com/guides/templates/rendering-with-helpers/
Upvotes: 3