【发布时间】:2019-03-22 19:27:29
【问题描述】:
如何检查 twig 中的多个 if 条件? 这些似乎都不起作用 而且它们看起来都很凌乱和沉重。
{% if pageClass != "page-home" %}
{% if bodyClass != "500" %}
{% if bodyClass != "404" %}
{% include '_components/type-bg' with {
content: {
slug: entry.slug|split(' ')|slice(0, 1)|join
},
} only %}
{% endif %}
{% endif %}
{% endif %}
我也试过下面的
{% if (pageClass != "page-home") or (if bodyClass != "500") or (if bodyClass != "404")%}
{% include '_components/type-bg' with {
content: {
slug: entry.slug|split(' ')|slice(0, 1)|join
},
} only %}
{% endif %}
【问题讨论】:
-
@LeKhan9 不。我上面的示例表明我已经尝试过该解决方案,但它不起作用
-
@Jessica 不应该是
and而不是or? -
@Iwan-Wijaya 我想检查这些条件是否为真。如果其中任何一个为真,则将此模板包含在内容中。一个页面不能是 500 404 和 page-home :-/
-
哦,我没有看值,我认为你的第一个代码中的逻辑是正确的。我认为应该是
{% if pageClass != "page-home" or bodyClass != "500" or bodyClass != "404 %}?
标签: symfony twig octobercms craftcms