[SOLVED]Getting template's paramaters and options


#1

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?


#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" }
  }
});

#3

:smiley: Thank for your help! it work for me and I understand better how templates work.