3

在子布局中,是否可以定义一个 frontmatter 变量,其范围仅限于使用此布局的模板?

例如,给定一个子布局 child.hbs:

---
layout: parent.hbs
layout_script: childScript.js
---

和父布局parent.hbs:

{{#if layout_script}}
<script src="assets/js/{{layout_script}}">
{{/if}}

我希望我的父布局在从 child.hbs 继承的页面上包含脚本标记。相反,layout_script它变成全局的,并且脚本在所有使用 parent.hbs 的页面上输出。

作为参考,父布局的实际代码在这里。我们希望脚本仅在使用子布局好处.hbs的页面上构建。

相关问题

4

2 回答 2

1

assemble 0.4.x 中存在一个错误,其中数据在页面之间持续存在,因为它在构建期间扩展到了全局上下文中。这是我们在下一个版本中修复的问题,但在 0.4.x 中不可用。

作为一种解决方法,您应该能够layout_script在任何其他子布局中进行设置,false以便它不会被使用:

---
layout_script: false
---
于 2014-07-10T18:47:03.880 回答
0

我认为您需要将您的 parent.hbs 更改为以下内容:

{{#if data.layout_script}}
<script src="assets/js/{{layout_script}}">
{{/if}}

看看这是否有效。

于 2014-07-02T17:22:23.287 回答