How to get parameters from a template inclusion?
{{> myTemplate options="oneOfPossibleOptions"}}
I have a template that expects some options like this:
'optionOne':function(){return 'do something'},
'optionTwo':function(){return 'do something else'}
Now, I need to get those options from myTemplate.js. I tried to get it from myTemplate.helpers but it doesn’t work. What is the common way to achieve this purpose?
manuel
October 11, 2015, 8:46pm
2
<body>
{{> myTemplate options="oneOfPossibleOptions"}}
</body>
<template name="myTemplate">
{{info}}
<button>Log info</button>
</template>
Template.myTemplate.onCreated(function(){
console.log(this.data); // { options: "oneOfPossibleOptions" }
});
Template.myTemplate.onRendered(function(){
console.log(this.data); // { options: "oneOfPossibleOptions" }
});
Template.myTemplate.helpers({
info: function(){
return Template.instance().data.options; // "oneOfPossibleOptions"
}
});
Template.myTemplate.events({
'click button': function(){
console.log(Template.instance().data); // { options: "oneOfPossibleOptions" }
}
});
1 Like
Thank for your help! it work for me and I understand better how templates work.