[英]Twig data deeply nested - variable name lengths?
I have a very deeply nested data structure and the variable names in my Twig template are getting quite long. 我有一个非常嵌套的数据结构,并且Twig模板中的变量名越来越长。
In Mustache, you can "delimit" the data using the {{# variable }}
and everything inside that you wouldn't have to "prefix" with that variable, like this: 在Mustache中,您可以使用
{{# variable }}
对数据进行“定界”,而其中的所有内容都无需使用该变量“前缀”,例如:
data: 数据:
variable1
variable2
variable2_1
variable2_2
variable3
variable3_1
variable3_2
variable3_3
Mustache template: 小胡子模板:
{{# variable1}}
<element>{{variable2}}</element>
<element>{{variable3.variable3_3}}</element>
{{/ variable1}}
In the above, you don't have to prefix the variable2
and variable3.variable3_3
with variable1
. 在上面,您不必在
variable2
和variable3.variable3_3
前面加上variable1
。
Here's an example of one data element that I have: ProcNoStsRq.ProcFold.Header.Admin.Sup.Pty.Contact.Comms.SA.Address.City
(note that this one is shortened from the 122 characters of the real variable name) 这是我拥有的一个数据元素的示例:
ProcNoStsRq.ProcFold.Header.Admin.Sup.Pty.Contact.Comms.SA.Address.City
(请注意,此变量比实变量名称的122个字符缩短了)
I know I'm going to have some that are even deeper. 我知道我会更深入一些。 How can I achieve the same in Twig?
如何在Twig中实现相同目标?
不要以为您可以直接做到这一点,但是如果您使用include,则可以使其正常工作。
{% include "template.twig" with { 'variable2' : variable1.variable2, } %}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.