我开始在我的 Meteor 应用程序中使用Iron Router及其yields
模板。
我最近遇到了一个问题,我无法使用上下文启动命名收益,如下所示:
{{#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 项目上,但尚未得到任何解决方案。
将不胜感激任何帮助。
编辑 1/1/2014:所以我的代码如下所示:
// 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 个不同的部分模板,我必须把它放在所有模板中。