Skip to content

Instantly share code, notes, and snippets.

@aaronthorp
Created March 26, 2015 12:14
Show Gist options
  • Save aaronthorp/d702e6036e4b06ecdd41 to your computer and use it in GitHub Desktop.
Save aaronthorp/d702e6036e4b06ecdd41 to your computer and use it in GitHub Desktop.
blaze-parentTemplate.js
/**
* Get the parent template instance
* @param {Number} [levels] How many levels to go up. Default is 1
* @returns {Blaze.TemplateInstance}
*/
Blaze.TemplateInstance.prototype.parentTemplate = function (levels) {
var view = Blaze.currentView;
if (typeof levels === "undefined") {
levels = 1;
}
while (view) {
if (view.name.substring(0, 9) === "Template." && !(levels--)) {
return view.templateInstance();
}
view = view.parentView;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment