Is there any way to pass a variable context to the {{render}}
helper?
For instance, I have a polymorphic relationship on my model, and I want to render the appropriate view for each different type (without have to write a whole string of if
statements.
my events
template looks like this:
<ul>
{{#each event in model}}
<li>
{{event.time}} {{render event.type event.eventable}}
</li>
{{/each}}
</ul>
the event.type
is a string and is set to song
. If I use {{render 'song' event.eventable}}
everything works great. But passing the variable string 'song'
produces nothing.
Can this be done?
You can achieve this by writing your own Handlebars Helper which determines the template to render and then delegates to the build in render helper. Try this:
Then in your template you would call the template as follows: