Created
March 26, 2015 12:14
-
-
Save aaronthorp/d702e6036e4b06ecdd41 to your computer and use it in GitHub Desktop.
blaze-parentTemplate.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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