ember.js - Calling Handlebars {{render}} with a variable name -
is there way pass variable context {{render}}
helper?
for instance, have polymorphic relationship on model, , want render appropriate view each different type (without have write whole string of if
statements.
my events
template looks this:
<ul> {{#each event in model}} <li> {{event.time}} {{render event.type event.eventable}} </li> {{/each}} </ul>
the event.type
string , set song
. if use {{render 'song' event.eventable}}
works great. passing variable string 'song'
produces nothing.
can done?
you can achieve writing own handlebars helper determines template render , delegates build in render helper. try this:
ember.handlebars.registerboundhelper('renderevent', function(callingcontext, event, options) { return ember.handlebars.helpers.render.call(callingcontext, event.get('type'), 'eventable', options); });
then in template call template follows:
{{#each event in model}} {{renderevent event}} ((/each}}
Comments
Post a Comment