doujinai2183 2018-10-12 15:00
浏览 46
已采纳

Twig数据深层嵌套 - 变量名称长度?

I have a very deeply nested data structure and the variable names in my Twig template are getting quite long.

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:

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.

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)

I know I'm going to have some that are even deeper. How can I achieve the same in Twig?

  • 写回答

1条回答 默认 最新

  • douyan1244 2018-10-15 06:04
    关注

    Don't think think you can do this straight up, but if you use includes u could make it work.

    {% include "template.twig" with { 'variable2' : variable1.variable2, } %}

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里