Twig 在页面上发布空模块
Twig posting empty modules on page
我在 Craft 中使用 Twig 并尝试包含我制作的模块,我已将所有内容添加到 CMS 的模块中并保存,它们正确显示在页面上,但是还显示大量空段落标签,有人知道这是为什么吗?
我采取的步骤:
我有一个名为 "Abilities.twig" 的 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 个示例,没有保存空模块。
如有大神帮忙将不胜感激
如果您不想要 "extra" <p>
,您需要验证内容是否为空
{% if module.Abilities | trim != '' %}
<p>{{ module.Abilities }}</p>
{% endif %}
您可以在循环中添加 if 语句
{% for module in entry.modals if module != null %}
{% include '_modals/Abilities' %}
{% endfor %}
我在 Craft 中使用 Twig 并尝试包含我制作的模块,我已将所有内容添加到 CMS 的模块中并保存,它们正确显示在页面上,但是还显示大量空段落标签,有人知道这是为什么吗?
我采取的步骤:
我有一个名为 "Abilities.twig" 的 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 个示例,没有保存空模块。
如有大神帮忙将不胜感激
如果您不想要 "extra" <p>
,您需要验证内容是否为空
{% if module.Abilities | trim != '' %}
<p>{{ module.Abilities }}</p>
{% endif %}
您可以在循环中添加 if 语句
{% for module in entry.modals if module != null %}
{% include '_modals/Abilities' %}
{% endfor %}