lundi 26 janvier 2015

render different components based on presence of attribute

I'm doing something dumb in that I'm storing records with different attributes in a single model, which means that some of the records have certain attributes that others don't. The reason i'm doing this is so that I can render them all in a single list ordered by date. I realize this likely isn't the right way to do things, but until I figure out that right way, I need to find a way for Handlebars that will render a different component based on the presence or absence of an attribute in the model.


I've tried something like this but can't get it to work. How would I manage that?


pseudo-code



{{#each item in arrangedContent}}

{{if item.baz }}

<li> {{custom-component-a id=item.customid unique-attribute=item.baz date=item.date data=item.stats}}</li>

{{else if item.foo}}

<li> {{custom-component-b id=item.customid unique-attribute=item.foo date=item.date data=item.stats}}</li>

{{else if item.bar}}

<li> {{custom-component-c id=item.customid unique-attribute=item.bar date=item.date data=item.stats}}</li>

{{/if}}


{{/each}}




Aucun commentaire:

Enregistrer un commentaire