[英]Twig check if value in array is true
我有一個包含布爾值的數組。 如何搜索數組以查看一個或多個是否為真,然后顯示<h1>
一次?
到目前為止,這是我的代碼
{% set guides =
[
product.is_user_guide,
product.is_product_guide,
product.is_installation_guide
]
%}
{% for guide in guides %}
{% if (guide) %}
<h1>There is a guide!</h1>
{% endif %}
{% endfor %}
在上面的代碼中,它在數組中找到2個值為true,並顯示h1兩次。 如何修改它只顯示一次?
{% set guides = [
product.is_user_guide,
product.is_product_guide,
product.is_installation_guide
] %}
{% if true in guides %}
<h1>There is a guide!</h1>
{% endif %}
演示: http : //twigfiddle.com/pf4xjp
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.