我有一些对象,例如地址1,地址2,地址3 ...地址10。所有这些对象都具有lat
和long
值。
我知道我们可以从attribute()
Twig的功能中获取它,但是我想要在Twig模板中获取主要对象
{% for i in 1..10 %}
{% set address = address~i %}
{{ address.lat }}
// or like
{{ attribute(address, 'lat') }}
{% endfor %}
只需简单地使用:
{% for i in 1..10 %}
{{ attribute(attribute(_context, 'address'~i), 'lat') }}
{% endfor %}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句