frozeman/meteor-template-var

Feature request: accessing parent template variable

Opened this issue · 1 comments

I think this package is the natural place for a function everyone uses (see below), nicely integrated with the package API.

// Returns an ancestor instance of the current template instance (by name)
// See
// https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/meteor-core/H9XUndnLpf0/N_hp69p9SsEJ
Blaze.TemplateInstance.prototype.parentInstance = function (templateName) {
  if (! /^Template\./.test(templateName))
    templateName = 'Template.' + templateName;
  var view = this.view;
  while (view = view.parentView)
    if (view.name === templateName)
      return view.templateInstance();
};