Twig 在页面上张贴空模块

我在 Craft 中使用 Twig 并尝试包含我制作的模块,我已将所有内容添加到 CMS 中的模块中并保存,它们正确显示在页面上,但有大量空段落标签还显示,有谁知道这是为什么?


我采取的步骤:


我有一个名为“Abilities.twig”的树枝文件,在能力中我有以下代码:


<p>{{ module.Abilities }}</p>

在 Index.twig 我有以下内容:


{% for module in entry.modals %}

    {% include '_modals/Abilities' %}

{% endfor %}

下面是它们如何在页面上显示的示例


<p>This is the first example of an ability</p>

<p>This is the second example of an ability</p>

<p></p>

<p></p>

<p></p>

<p></p>

<p></p>

在 CMS 中,唯一显示的模块是前 2 个示例,没有保存空模块。


如果有人可以帮助将不胜感激


九州编程
浏览 129回答 2
2回答

暮色呼如

如果您不想拥有“额外” <p>,则需要验证内容不为空{% if module.Abilities | trim != '' %}&nbsp; &nbsp; <p>{{ module.Abilities }}</p>{% endif %}

GCT1015

您可以在循环中添加 if 语句{% for module in entry.modals if module != null %}&nbsp; &nbsp; {% include '_modals/Abilities' %}{% endfor %}
打开App,查看更多内容
随时随地看视频慕课网APP