How to get helper in oncreate


#1

I’m using Template subscribe in oncreate.
If I want to get the helper value I have to use Template.currentData() which is reactive.
And when I use it with Tracker. The console just keep getting the data.

var parentType = Template.instance().parentType;
self.autorun(function(){
console.log(parentType);
})


#2

Sorry, I don’t understand. Maybe you can provide a piece of non-working code?


#3

Template.volunteerTakeInsert.onCreated(function(){
var self = this;
// self.state
var parentType = Template.currentData().parentType;
var parent_id = Template.currentData().parent_id;
self.autorun(function(){
var volunteerTake;
if( parentType!=undefined
&& parent_id !=undefined ){
console.log(parentType);

And that the console will push hundreds of times


#4

What do you want to achieve?


#5

I get two helper passing by the parent helper : parentType and parent_id.
I want to use this two helper to controlthe subscription in volunteerTakeInsert.

First I can’t get helper in oncreated
so I use currentData.

But it renders hundreds time in the autorun


#6

Nothing in the code you posted would trigger the autorun hundreds of times. I suggest you create a meteorpad to show your problem.


#7

I suggest googling how to check undefined status.
And show us how you render that template so we see how you pass the variables.


#8

Thanks I got it working. My fault!