dimanche 11 janvier 2015

Using named-parameter flavor of #each helper together with a generic partial

In my application I have different node types, which share a similar structure. For that I am using a template like this:



{{#each model}}
<td>{{name}}</td>
... {{! more properties specific to this node (agent) }}
{{partial "common/output_cells"}}
{{/each}}


With common/output_cells being:



{{#if controller.startnodeAllowed}}<td>{{#if outputs§startnode}}{{#link-to startNodeRoute outputs§startnode}}{{view "nodeIcon" nodeIdBinding="outputs§startnode"}}{{/link-to}}{{else}}{{view "nodeIcon"}}{{/if}}</td>{{/if}}
... {{! other common properties for all nodes (lots of them)}}


Now I am transitioning to named-parameter helpers, so I have:



{{#each agent in content}}
<td>{{agent.name}}</td>
... {{! more properties specific to this node (agent) }}
{{partial "common/output_cells"}}
{{/each}}


And I am forced to change the common partial:



{{#if controller.startnodeAllowed}}<td>{{#if agent.outputs§startnode}}{{#link-to agent.startNodeRoute agent.outputs§startnode}}{{view "nodeIcon" nodeIdBinding="agent.outputs§startnode"}}{{/link-to}}{{else}}{{view "nodeIcon"}}{{/if}}</td>{{/if}}
... {{! other common properties for all nodes (lots of them)}}


But this makes my common/output_cells partial tied to an agent, while it should be tied to a generic node. Is it possible to call partial as follows (I made up the syntax, since I do not know how to do this)?



{{partial "common/output_cells" with agent as node}}


So that I can implement the partial in a more generic way:



{{#if controller.startnodeAllowed}}<td>{{#if node.outputs§startnode}}{{#link-to node.startNodeRoute node.outputs§startnode}}{{view "nodeIcon" nodeIdBinding="node.outputs§startnode"}}{{/link-to}}{{else}}{{view "nodeIcon"}}{{/if}}</td>{{/if}}
... {{! other common properties for all nodes (lots of them)}}


If this is not possible, what other options do I have in order to reuse the partial?


Aucun commentaire:

Enregistrer un commentaire