如何根据Meteor中的条件停止渲染模板

时间:2015-02-21 15:41:18

标签: meteor

在某些情况下Meteor中是否有办法停止渲染模板?我发现这有效:

Template.test.created = function () {
    if (/* conditions */) {
        this.view.template.renderFunction = function () {
            return null;
        };
    }
};

但是......也许有人能做得更好吗?

1 个答案:

答案 0 :(得分:0)

最好在模板/助手本身内完成此任务。

<template name="sometimesVisible">
  {{#if visible}}
    <!-- content here -->
  {{/if}}
</template>

Template.sometimesVisible.helpers({
  visible: function() {
    // conditions here
  }
]);