How to pass multiple arguments to Spacebars helper from Meteor template? -
i haven't been able find solid example out there.
template.registerhelper("itemlookup", function(sku, property){ return items.findone({sku: sku})[property]; });
how call on template?
i want like:
{{ itemlookup sku="i3_4030u" property="title" }}
it should output
"intel core i3 4030u"
do not name template helpers parameters, passed in same order helper function :
{{ itemlookup "i3_4030u" "title" }}
edit :
why see examples online naming template helper parameters?
you can name parameters when including template , want set current data context else :
{{> childtemplate param1="a" param2="b"}}
in child template markup you'll able reference {{param1}}
, {{param2}}
.
another handlebars helpers feature available in spacebars "hash" optional argument value can pass last argument helper parameters, can use :
html
{{helper "a" "b" namedparam1="c" namedparam2="d"}}
js
template.registerhelper("helper", function(param1, param2, options){ console.log("param1 :", param1); console.log("param2 :", param2); if(options && options.hash){ console.log("namedparam1 :", options.hash.namedparam1); console.log("namedparam2 :", options.hash.namedparam2); } });
Comments
Post a Comment