【发布时间】:2014-01-02 07:27:16
【问题描述】:
我开始在我的 Meteor 应用程序中使用 Iron Router 及其 yields 进行模板化。
我最近遇到了一个问题,我无法使用上下文启动命名 yield,如下所示:
{{#with context}}
{{yield 'subtemplate'}}
{{/with}}
得到这个错误Sorry, couldn't find a yield named "subtemplate". Did you define it in one of the rendered templates like this: {{yield "subtemplate"}}?
如果我删除 {{#with}} 块表达式,我就可以渲染产量。
有谁知道将上下文传递给命名收益的好方法吗?
我在iron-router github 项目上以an issue 的身份发布了我的问题,但还没有得到任何解决方案。
不胜感激。
2014 年 1 月 1 日编辑: 所以我的代码如下所示:
// main template for the route
<div class="form-container">
<div class="form">
{{yield 'section'}}
</div>
</div>
显示收益部分的逻辑
// router.js
ApplyController = RouteController.extend({
before: function() {
var section = this.params.section || 'personal-info';
Session.set('current', section);
},
action: function() {
var section = Session.get('current');
this.render();
this.render(section, {
to: 'section'
});
},
data: function() {
return {
app: Applications.findOne({user: Meteor.userId()})
}
}
});
部分模板的示例:
<template name="education">
{{#with app}}
<form id="education" name="education" class="fragment" method="post" action="">
<h2>Education</h2>
<div class="form-group">
<label for="college" class="control-label">College/ University</label>
<select class="form-control" id="college" name="college" placeholder="Select a College/ University">
<option value="">Select a College/ University</option>
{{#each colleges}}
<option value="{{slug}}" {{selected slug ../college}}>{{name}}</option>
{{/each}}
</select>
</div>
<!-- other content here -->
</form>
{{/with}}
</template>
使用{{#with app}} 块是我目前解决此问题的方法,但因为我有 10 个不同的部分模板,所以我必须将其放入所有模板中。
【问题讨论】:
标签: meteor iron-router