我正在建立一个网站,我想要有一个布局包装器为大多数页面(但不是所有)。我想要做的是为布局包装器使用partial,然后将其他内容partial传递到这个主布局中。
layout.hbs的内容
<!DOCTYPE html>
<html>
{{> head }}
<body>
{{> nav}}
{{ content }}
</body>
</html>然后在somefile.hbs中
{{> layout myPartial.hbs}}我正在大吃一惊地渲染我的车把模板。
如果我将标记直接传递到layout.hbs中,我可以让它工作,但我想要做的是将另一个局部文件的内容传递到布局包装器中。
{{> layout content="<div>foo</div>"}} // Renders ok有没有其他方法可以让我接近全局布局包装器?
发布于 2018-04-07 06:09:33
我能够通过dynamic partial lookup syntax让它工作起来。
工作解决方案
layout.hbs的内容
<!DOCTYPE html>
<html>
{{> head }}
<body>
{{> nav}}
{{> (lookup . 'partial') }}
</body>
</html>someFile.hbs的内容
// Allows me to hit http://w.x.y.z/someDir/someFile
{{> layout partial='someDir/_someFile'}}someDir/_someFile.hbs的内容
// Content injected into the layout and can include nested layouts
<h1>Some content I want to render</h1>https://stackoverflow.com/questions/49681560
复制相似问题