为了账号安全,请及时绑定邮箱和手机立即绑定

Twig 在页面上张贴空模块

Twig 在页面上张贴空模块

PHP
九州编程 2021-10-08 21:17:40
我在 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 个示例,没有保存空模块。如果有人可以帮助将不胜感激
查看完整描述

2 回答

?
暮色呼如

TA贡献1853条经验 获得超9个赞

如果您不想拥有“额外” <p>,则需要验证内容不为空


{% if module.Abilities | trim != '' %}

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

{% endif %}


查看完整回答
反对 回复 2021-10-08
?
GCT1015

TA贡献1827条经验 获得超4个赞

您可以在循环中添加 if 语句


{% for module in entry.modals if module != null %}

    {% include '_modals/Abilities' %}

{% endfor %}


查看完整回答
反对 回复 2021-10-08
  • 2 回答
  • 0 关注
  • 127 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信