Meteor:如何直接访问 Blaze 中模板的实例密钥(无需帮助)?

Meteor: How to access Template's Instance key in Blaze directly (without helper)?

Template.Demo.onCreated(function() {
    this.test = 'Text';
});

如何在 Blaze 中直接访问该模板的实例 test 键(无需创建辅助函数)?

{{Template.instance.test}} 好像不行(建议here)。

我认为当前版本的 Blaze 无法做到这一点。也就是说,您可以通过声明一个全局模板辅助函数来模拟这一点,例如:

Template.registerHelper('instance', function () {
  return Template.instance();
});

只需在公共客户端位置定义一次,然后您就可以在任何模板中引用 instance。所以你可以像这样引用你的 test 变量:

{{instance.test}}