symfony - 如何检查树枝中的多个 if 条件?
问题描述
如何检查树枝中的多个 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 %}
解决方案
你需要and
用作你的all condition need to satisfy
,execute that code
所以它必须是and
{% if pageClass != "page-home" and bodyClass != "500" and bodyClass != "404" %}
{% include '_components/type-bg' with {
content: {
slug: entry.slug|split(' ')|slice(0, 1)|join
},
} only %}
{% endif %}
更好的解决方案是
code block
只使用 PHP 代码 [你可以在这里做所有 PHP 的东西] 来实现这一点,switch case or etc ..
并且只传递像布尔值这样的标志来查看并使用它。needToInclude
{% if needToInclude %}
{% include '_components/type-bg' with {
content: {
slug: entry.slug|split(' ')|slice(0, 1)|join
},
} only %}
{% endif %}
如有任何疑问,请发表评论
推荐阅读
- protractor - 角度测试 - 将 Jest 与量角器一起使用
- angular - 模态控制器在离子科尔多瓦中不起作用
- sql-server - 如何在 AVG() 函数 SQL Server 中表示 0.5 或 1/2
- visual-studio-code - VSCode 一些快捷键不能正常工作
- rust - 调用返回字符串字面量数组的函数,出现“无法返回引用局部变量的值”错误
- python - 收到导入 scipy.signal 的错误
- php - 如何使用 PHP/SQL 在 Azure SQL 表中选择包含“#”的行?
- mysql - 无法在 xampp 中启动 mysql
- reactjs - React.JS,TypeError:this.state.movies.map 不是函数问题
- firebase - 有什么方法可以实时从 Firebase Analytics 日志事件中获取数据?