javascript - Passing template instance data as a keyword argument to a nested template -


i have template, called skillbar, takes 2 keyword arguments, title , value.

so, example, type:

  {{>skillbar title="strength"  value=51}} 

to render skillbar label "strength" has progress bar filled 51%.


i have bunch of these skillbars create , rather doing like:

{{>skillbar title="strength"     value=51}} {{>skillbar title="willpower"    value=80}} {{>skillbar title="imagination"  value=30}} 

id rather create separate template, can register helper on contains array of objects can use parameters.

template.abilities.helpers({   abilities: [     {title: 'strength',    value: 51},     {title: 'willpower',   value: 80},     {title: 'imagination', value: 30}    ] });  

presumably then, {{#each}} on abilities array in markup can create skillbar template instances way.

this encapsulates essence of want do, throws syntax error:

<template name="abilities">   {{#each abilities}}     {{>skillbar title={{title}} value={{value}} }}   {{/each}} </template> 

use syntax instead :

<template name="abilities">   {{#each abilities}}     {{> skillbar}}   {{/each}} </template> 

when invoking child template, if don't pass argument current data context set parent one, happens iterated on ability {{#each}} loop.

alternatively use syntax :

<template name="abilities">   {{#each abilities}}     {{> skillbar title=title value=value}}   {{/each}} </template> 

but in specific case redundant, useful rename parameters whatever reason.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -