Using a method
<template name="parent">
<h2>parent template</h2>
<p>{{ simpleMethod }}</p>
<p>{{ methodReceivingParam "foo" "bar" "baz" }}</p>
<!-- this will throw an error!
<p>{{ methodReceivingParam "foo" "bar" "baz" }}</p>
-->
<!-- this will return "method receiving params: , , " because foo, bar and baz evaluate to falsey
<p>{{ methodReceivingParam foo bar baz }}</p>
-->
run this test:
<p>{{ methodForHashAndParam foo="foo val" bar="bar val" }}</p>
</template>
Template.parent.helpers({
simpleMethod: function() {
return "simple method result";
},
methodReceivingParams: function() {
var args = Array.prototype.slice.call(arguments);
console.log(args.pop());
// the final argument that gets passed is Spacebars.kw object
return "method received param: " + args.join(', ');
},
});
parent template
simple method result
method received param: foo, bar, baz