当{% for ... %}
在包含的 nunjucks 模板(例如{% include ... %}
)中使用循环时,循环的生成内容将呈现在<pre><code>...</code></pre>
块内。
这是包含的内容:
src/includes/recipe-ingredients.html
<aside id="ingredients" aria-label="ingredients">
<h3>Ingredients</h3>
<ul>
{% for ingredientData in recipe.ingredients %}
<li><span class="measure">{{ ingredientData.displayQty }}</span>
<span class="ingredient">{{ ingredientData.ingredient }}</span></li>
{% endfor %}
</ul>
</aside>
...这就是生成的内容:
<!-- Rest of generated HTML -->
<aside id="ingredients" aria-label="ingredients">
<h3>Ingredients</h3>
<ul>
<pre><code><li><span class="measure">2</span>
<span class="ingredient">cinnamon</span></li>
<li><span class="measure">3/4</span>
<span class="ingredient">sugar</span></li>
</code></pre>
</ul>
</aside>
<!-- Rest of generated HTML -->
为什么会发生这种情况,我该如何预防?