简体   繁体   English

车把的局部

[英]handlebars partial inside of a partial

I'm building out a site where I want to have a layout wrapper for most pages (but not all). 我正在建立一个站点,希望为大多数页面(但不是全部)提供一个布局包装器。 What I'm trying to do is use a partial for the layout wrapper and then pass other content partials into this master layout. 我正在尝试做的是将部分内容用于布局包装器,然后将其他内容部分内容传递到此主布局中。

Contents of layout.hbs layout.hbs内容

<!DOCTYPE html>
<html>
    {{> head }}
    <body>
        {{> nav}}
        {{ content }}
    </body>
</html>

Then in somefile.hbs 然后在somefile.hbs

{{> layout myPartial.hbs}}

I'm rending my handlebars templates with gulp. 我正在用gulp出租车把模板。

I can get this working if I pass markup directly into layout.hbs but what I'd like to do is pass the contents of another partial file into the layout wrapper. 如果将标记直接传递到layout.hbs则可以正常工作,但我想做的是将另一个部分文件的内容传递到布局包装器中。

{{> layout content="<div>foo</div>"}} // Renders ok

Is there another way I should be approaching a global layout wrapper? 我应该采用另一种方式访问​​全局布局包装器吗?

I was able to get this working with dynamic partial lookup syntax . 我能够使用动态局部查找语法来实现这一点。

Working solution 工作方案

Contents of layout.hbs layout.hbs内容

<!DOCTYPE html>
<html>
    {{> head }}
    <body>
        {{> nav}}
        {{> (lookup . 'partial') }}
    </body>
</html>

Contents of someFile.hbs someFile.hbs内容

// Allows me to hit http://w.x.y.z/someDir/someFile
{{> layout partial='someDir/_someFile'}}

Contents of someDir/_someFile.hbs someDir/_someFile.hbs

// Content injected into the layout and can include nested layouts
<h1>Some content I want to render</h1>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM