Extensions to templates to make it easier to get child and parent templates.
meteor add workman:templating-ext
Finds child template instance by name. Returns null if a matching templating is not found.
<template name="parent">
{{> child}}
<button id="done"></button>
</template>
<template name="child">
<input>
</template>
Template.child.created = function () {
this.value = new Blaze.ReactiveVar();
};
Template.child.events({
'input input': function (e, tmpl) {
tmpl.value.set($(e.target).val());
}
});
Template.parent.events({
'click #done': function (e, tmpl) {
var child = tmpl.findChildTemplate('child');
var val = child.value.get();
Collection.insert({ val: val });
}
});
Finds parent template instance by name. If the template name supplied matches the current template, it will return itself. Returns null if a matching template is not found. If templateName is not set, findParentTemplate
will return the first parent.
<template name="parent">
{{> child}}
</template>
<template name="child">
{{#if selectedVal}}
... do something.
{{/if}}
</template>
Template.parent.created = function () {
this.selectedVal = new Blaze.ReactiveVar();
};
Template.child.helpers({
'selectedVal': function (e, tmpl) {
return tmpl.findParentTemplate('parent').selectedVal.get();
}
});
Used internally by findChildTemplate.
Used internally by findParentTemplate.
jQuery function that returns a template instance for the first matching element from a jQuery selector, or null if one is not found.
var tmpl = $('#my-div').templateInstance();