Mossar
Mossar

Reputation: 435

MeteorJS - access to helpers of the same template

I'm working on a first project in meteor and I have trivial problem (I suppose it is easy to do) but I can't find proper way to do it right. This is simplified code in which I want to push some object to helper array.

Template.courses.helpers({
    doneCourses: [],
    init: function(){
        doneCourses.push({ title: this.name, date: this.endDate });      
    }
});

Unfortunatey i have error: "Exception in template helper: ReferenceError: doneCourses is not defined..". What is the proper way to do it? I want to show doneCourses on HTML with

{{ #each doneCourses }}

but I have to get it from database on the beginning. Additional question - what is the best way to do init functions? Do it in iron router data field or make separate init function?

Upvotes: 0

Views: 63

Answers (1)

Elie Steinbock
Elie Steinbock

Reputation: 5088

doneCourse: function () { ... }

is the correct way to do things.

If you need to do stuff when the template is rendered or created you can use onRendered or onCreated that Template supplies.

Upvotes: 1

Related Questions