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

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -