In a child layout, is it possible to define a frontmatter variable whose scope is restricted to templates which use this layout?
For example, given a child layout child.hbs:
---
layout: parent.hbs
layout_script: childScript.js
---
And the parent layout parent.hbs:
{{#if layout_script}}
<script src="assets/js/{{layout_script}}">
{{/if}}
I want my parent layout to include the script tag only on pages which inherit from child.hbs. Instead, layout_script
becomes global and the script is outputted on all pages that use parent.hbs.
For reference, the actual code for parent layout is here. We want the script to be built out only on pages that use the child layout benefits.hbs.
There's a bug in assemble 0.4.x where the data persists across pages because it's extended into the global context during the build. This is something that we're fixing in the next version, but it's not available in 0.4.x.
As a work around, you should be able to set layout_script
in any other child layouts to false
so it won't be used:
---
layout_script: false
---