这个问题的原因是在 foreach 循环中无法获取值。解决方法是在 foreach 之前添加 null 判断。例如:
{% for item in array|default([]) %}
{% if item is not null %}
{{ item }}
{% endif %}
{% endfor %}
在此示例中,我们首先使用 |default([]) 过滤器来检查变量 'array” 是否为 null。之后,我们在循环中使用空值(null)的 if 语句来避免使用 null 值。 这样可以确保我们可以正确地获取值并避免出现 Shopware6 - not able to get values due to my foreach loop 的问题。