2
的給定一個PHP數組中的一個樹枝模板:查找,如果樹枝數組是空的非保護值
object(Drupal\Core\Template\Attribute)#1208 (1) {
["storage":protected]=> array(0) { }
}
我如何檢查是否有數組中沒有非保護的元素呢?我的想法是,我只能操作非保護值,所以如果只有受保護值存在,我可以假裝數組爲空。
到目前爲止,我的檢查如下:
{% if attributes is defined and attributes is not empty %}
<div{{ attributes }}>
{{ content }}
</div>
{% else %}
{{ content }}
{% endif %}
在其目前的形式,這將顯示<div>[Content]</div>
。相反,我想看到:[Content]
任何幫助嗎?