longshotlabs / meteor-template-extension

A Meteor package: Replace already defined templates, inherit helpers and events from other templates
https://atmospherejs.com/aldeed/template-extension
MIT License
220 stars 20 forks source link

Could you provide an example on how to properly use template.parent #37

Closed rufusthecat closed 9 years ago

rufusthecat commented 9 years ago

Hi Bit of a new guy on the block but can't find a good example on how to make template.parent work Do I put in in a helper function, on rendered and how is it returned Sorry for this basic question as I can't find a good sample to use so far I want it to access this helper on the parent template

Template.course.helpers({'builder' : function(itemType) {
    var courseBuilder = 'itemType';
    Session.set('builder', courseBuilder);
    return Session.get('builder') === itemType}
});```
aldeed commented 9 years ago

@rufusthecat template.parent actually gets the parent template instance, and is on a template instance. So assuming you have template variable which is the instance of a template within an instance of "course" (e.g., this within onRendered or using Template.instance()), then the parent helpers are on template.parent().template.__helpers property. But you might just want to inherit them on the child template with Template.child.inheritsHelpersFrom('course')

rufusthecat commented 9 years ago

Thanks for your feedback