树枝获取名称中带有“-”的对象
twig get object with "-" in name
像这样的 API return 对象
[attr] => stdClass Object
(
[id] => 555
[ttl] => 360
[aa-type] => NS
[prio] => 9
)
在我的 Twig 模板中,在 FOR 中,如何获得 aa 类型?
{{ value.attr.id }} -> ok
{{ value.attr.aa-type }} -> Nok because "-"
要访问具有特殊字符的对象的属性,您可以使用 attribute
函数
{{ attribute(value.attr, 'aa-type') }}
像这样的 API return 对象
[attr] => stdClass Object
(
[id] => 555
[ttl] => 360
[aa-type] => NS
[prio] => 9
)
在我的 Twig 模板中,在 FOR 中,如何获得 aa 类型?
{{ value.attr.id }} -> ok
{{ value.attr.aa-type }} -> Nok because "-"
要访问具有特殊字符的对象的属性,您可以使用 attribute
函数
{{ attribute(value.attr, 'aa-type') }}