javascript 带有流星和铁路由器的产量模板
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22585645/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Yield Templates with meteor and iron router
提问by Warz
I am using the new blaze-integration
branch of IR and have made the necessary changes for an existing application. I have in one of my templates a yield region:
我正在使用blaze-integration
IR的新分支,并对现有应用程序进行了必要的更改。我的一个模板中有一个产量区域:
<div>
{{> yield region='signup-detail'}}
</div>
I would like to set this region in a route configuration using yieldTemplates
. My route is configured like so:
我想在路由配置中使用yieldTemplates
. 我的路线配置如下:
this.route('signUpInfo', {
path: '/sign-up',
template: 'signUp-form',
yieldTemplates: _.extend({}, mainYieldTemplates, {
'information': {to: 'signup-detail'}
})
});
mainYieldTemplates = {
'footer': { to: 'footer' },
'header': {to: 'header'}
};
My template 'information' is not rendering into signup-detail
. Only happens with the new shark branch and IR blaze, has anything changed with Yield templates ?
我的模板“信息”未呈现为signup-detail
. 只有新的鲨鱼分支和 IR 火焰才会发生,Yield 模板有什么变化吗?
The footer and header templates are set correctly.
页脚和页眉模板设置正确。
EDIT: Template Layout
编辑:模板布局
<template name="basicLayout">
{{> yield region='header'}}
<div class="container">
<div class="row">
<div class="col-md-12 col-centered padding-top-four-em">
{{> yield}}
</div>
</div>
<hr>
<footer>
{{> yield region='footer'}}
</footer>
</div>
</template>
EDIT 2: SignUp Form template
编辑 2:注册表单模板
<template name="signUp-form">
<div class="col-md-12 signup-container">
{{>signUpSideBar}}
<div class="col-md-9 signup-content gray-border-box">
{{> yield region='signup-detail'}}
</div>
</div>
</template>
Note: The signUp-form template has a region signup-detail
. This is where my route signUpInfo
needs to render the information
template to that region. This used to work in IR before the blaze-integration.
注意:注册表单模板有一个区域signup-detail
。这是我的路线signUpInfo
需要将information
模板渲染到该区域的地方。这曾经在 blaze-integration 之前在 IR 中工作。
回答by Sajin M Aboobakkar
I don't know it's a perfect way to render.But it works for me
我不知道这是一种完美的渲染方式。但它对我有用
route.js
路由.js
Router.route('/', function () {
// use the template named ApplicationLayout for our layout
this.layout('ApplicationLayout');
// render the Post template into the "main" region
// {{> yield}}
this.render('Post');
// render the PostAside template into the yield region named "aside"
// {{> yield "aside"}}
this.render('PostAside', {to: 'aside'});
// render the PostFooter template into the yield region named "footer"
// {{> yield "footer"}}
this.render('PostFooter', {to: 'footer'});
});
ApplicationLayout.html
应用程序布局.html
<template name="ApplicationLayout">
<header>
<h1>{{title}}</h1>
</header>
<aside>
{{> yield "aside"}}
</aside>
<article>
{{> yield}}
</article>
<footer>
{{> yield "footer"}}
</footer>
</template>
main.html
主文件
<template name="Post">
<p>
{{post_content}}
</p>
</template>
<template name="PostFooter">
Some post specific footer content.
</template>
<template name="PostAside">
Some post specific aside content.
</template>
回答by bgmaster
Looks like your {{> yield region='signup-detail'}}
isn't in your yieldTemplate, so the router can't find the signup-detail region to insert your 'information' template.
看起来您{{> yield region='signup-detail'}}
不在您的 yieldTemplate 中,因此路由器找不到注册详细信息区域来插入您的“信息”模板。
{{> yield}}
in your yieldTemplate is rendering 'signUp-form' (from your template:
assignment in your route.
{{> yield}}
在您的 yieldTemplate 中呈现“signUp-form”(来自您template:
在路线中的分配。
If your 'signup-detail' template is a template within 'signUp-form', just use {{> signup-detail}}
.
如果您的“signup-detail”模板是“signUp-form”中的模板,只需使用{{> signup-detail}}
.
If you want 'signup-detail' to be re-used across multiple templates as a part of the layoutTemplate, then add {{> yield region='signup-detail'}}
to your yieldTemplate.
如果您希望将“signup-detail”作为 layoutTemplate 的一部分在多个模板中重复使用,请添加{{> yield region='signup-detail'}}
到您的 yieldTemplate。