【问题标题】:How to set a layout for a template using Blaze in Meteor?如何在 Meteor 中使用 Blaze 为模板设置布局?
【发布时间】:2015-05-01 12:29:45
【问题描述】:

我正在动态构建一些模板并尝试在我使用 Meteor 中的 Blaze 生成的 html 上设置布局,这就是我目前正在做的事情

Blaze.toHTML(Blaze.With(data, function() { return Template.my_template; }));

这会使用其中的数据从模板返回 html。我尝试在文档中搜索但我找不到它,那么有没有办法为这个模板设置布局?

我正在努力实现类似的目标

<template name="layout">
    <!-- some styling -->
    {{> yield}}
</template

并在生成 html 时使用它。

谢谢

【问题讨论】:

  • 你签出Iron Router了吗?
  • 他使用的是{{&gt; yield}},所以他已经拥有了iron:router

标签: meteor meteor-blaze


【解决方案1】:

改用Blaze.render()Blaze.renderWithData()

在模板中设置一个 DOM 节点:

<template name="layout">
<!-- some styling -->
<div id="foo"></div> <!-- this will be used like a yield -->
</template

然后在你的js中:

Template.layout.onRendered(function(){
  Blaze.render('otherTemplate',$('#foo')[0]);
});

【讨论】:

    猜你喜欢
    • 2016-03-24
    • 2016-11-19
    • 1970-01-01
    • 2016-03-07
    • 2014-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多