问题 与流星和铁路由器的屈服模板


我正在使用新的 blaze-integration IR的分支并对现有应用程序进行了必要的更改。我在我的一个模板中有一个yield区域:

<div>
        {{> yield region='signup-detail'}}
</div>

我想在路由配置中使用设置此区域 yieldTemplates。我的路线配置如下:

this.route('signUpInfo', {
        path: '/sign-up',
        template: 'signUp-form',
        yieldTemplates: _.extend({}, mainYieldTemplates, {
            'information': {to: 'signup-detail'}
        })
    });

mainYieldTemplates = {
    'footer': { to: 'footer' },
    'header': {to: 'header'}
};

我的模板“信息”未呈现 signup-detail。只有新的鲨鱼分支和IR火焰发生,使用Yield模板有什么变化吗?

页脚和页眉模板设置正确。

编辑:模板布局

<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>

编辑2:SignUp表单模板

<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>

注意:signUp-form模板有一个区域 signup-detail。这是我的路线 signUpInfo 需要渲染 information 该地区的模板。这曾经在火焰整合之前在IR中工作。


5013
2018-03-23 00:49


起源

你有这个工作吗?我在屈服区域遇到了麻烦,但复制了你所做的并且它对我有用。 - bgmaster
@bgmaster,我仍然没有这个工作。我在用 action 渲染我的区域而不是 yieldTemplates 现在选择。我试图孤立这个问题,看看哪里出了问题 - Warz
你可以发布你的整个layoutTemplate吗? - bgmaster
@bgmaster我添加了我用于95%路由的布局模板。 - Warz
回答下面...... - bgmaster


答案:


我不知道它是一种完美的渲染方式。但它对我有用

route.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

<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>

9
2018-02-05 19:50





看起来像你的 {{> yield region='signup-detail'}} 不在您的yieldTemplate中,因此路由器无法找到注册详细信息区域来插入“信息”模板。

{{> yield}} 在你的yieldTemplate中呈现'signUp-form'(来自你的 template: 在你的路线中分配。

如果您的“注册详细信息”模板是“signUp-form”中的模板,请使用 {{> signup-detail}}

如果您希望在多个模板中重复使用'signup-detail'作为layoutTemplate的一部分,那么添加 {{> yield region='signup-detail'}} 到你的yieldTemplate。


0
2018-04-24 15:55



我不认为我理解你的解决方案。我已经更新了我的问题,以向您展示模板 signUp-form 好像 - Warz
删除行:{{> yield region ='signup-detail'}},而只使用{{> signup-detail}}。这应该解决问题。 yield区域仅适用于layoutTemplates ... signUp-form是常规模板,而不是layoutTemplate。 - bgmaster
如果我只是使用 {{> signup-detail}} 那么我只能有一个名为的模板 signup-detail 我的内心 div.signup-content。我想要做的是在div中为不同的路线渲染不同的模板。那有意义吗 ?我想要治疗 signUp-form 像布局模板。 - Warz
我明白了,所以你基本上想要嵌套的布局模板,对吗?我不知道这是可能的,但我也没有尝试过。您是否尝试通过github联系具有事件意识的人?对于临时解决方案,您可以拥有多个布局模板。复制'basicLayout',为其添加'signUp-form',并将其重命名为'basicSignUpLayout'。然后,在您的路线中,只需添加“layoutTemplate:'basicSignUp-form'”行。它不是最优雅的解决方案,但它可以让你达到你想要的目标。 - bgmaster
是的,我正在寻找嵌套的布局模板,我认为这些模板在某一点上有效。我在github解决方案上提出了一个问题,但它没有任何牵引力。就像我说的,我正在使用 action 用于渲染模板的函数 - Warz