In Meteor, we can pass values to a helper like so:
{{testHelper abc="123" xyz="987"}}
and the helper:
Template.registerHelper('testHelper', function(opt) {
console.log(opt.hash.abc);
console.log(opt.hash.xyz);
});
Is there a way to do just:
{{testHelper "123" "987"}}
and get the values back as an index instead? Like so:
Template.registerHelper('testHelper', function(opt) { console.log(opt.hash[0]); console.log(opt.hash[1]); });
I know you can define a function which takes two arguments, like in this answer, and it'd work. But I'd ideally want the function to take any number of arguments.
If I console.log(opt);
here, I'd get 123
, whereas I want opt.hash[0]
(or, even better, opt[0]
) to be 123
, and opt.hash[1]
to be 987
.
The reason I want this is
"123"
looks cleaner thanabc="123"
when the key value doesn't matter,- but still allow the helper to accept any number of parameters.
I have tried passing an array as a parameter {{testHelper ["123", "987"]}}
, but that produced a syntax error.