这是我的用例
我有一个将各个部分组合在一起的文件(holy-grail.njs),然后由我想要的实际页面(single.njs)扩展。问题是包含文件中定义的块被实际页面模板忽略。您可以看到扩展侧边栏文本未出现在屏幕截图中 <p>Here is some additional content for the sidebar extended in</p>
只是为了笑,我将块代码从 sidebar.njs 移到了 Holy-grail.njs,是的,它由 single.njs 扩展,所以它确实是我所怀疑的。
是错误吗?,非功能?解决方法怎么样?或者翡翠会做我想做的事吗?我假设“包含”文件只是在进一步处理之前被包含,但也许它们被处理然后包含?如果无法做到这一点,我组织模板片段/部分然后扩展/自定义内容的整个常规方式将是行不通的。
三年前问过同样的问题,没有人回答 包含文件中的块没有被扩展模板填充
单.njs
{% extends "layouts/holy-grail.njs" %}
{% block sidebar %}
<p>Here is some additional content for the sidebar extended in</p>
{% endblock %}
{% block article %}
{% raw %}
{{ Hugo code here to grab the article title and content }}
{% endraw %}
{% endblock %}
圣杯.njs
{% set reg = "regions/" %}
{% set cmp = "components/" %}
{% include "regions/head.njs" %}
<body class='page'>
{% include reg + "header.njs" %}
<div class="rollover-wrapper">
{% include reg + "topbar.njs" %}
<main>
{% include reg + "sidebar.njs" %}
<section id="content">
{% block article %}
{# This is where one melds in article content #}
{% endblock %}
</section>
</main>
{% include reg + "footer.njs" %}
</div>
{% include cmp + "javascripts.njs" %}
</body>
侧边栏.njs
<aside id="sidebar" class="sidebar">
<p> some sidebar content set in the sidebar.njs file </p>
{% block sidebar %}
{# This is where one melds in more sidebar content #}
{% endblock %}
</aside>