简体   繁体   English

StringTemplate4 - 在变量中存储属性值

[英]StringTemplate4 - Storing attribute value in variable

I am injecting an attribute into my StringTemplate4 template which has multiple levels of sub-attributes.我将一个属性注入到我的 StringTemplate4 模板中,该模板具有多个级别的子属性。

As I work through the template outputting various elements of it I need to refer to attributes quite far down in the nesting at differing points, leading to the template quite often doing multiple references such as...当我通过模板输出它的各种元素时,我需要在不同点的嵌套中引用相当远的属性,导致模板经常进行多次引用,例如...

attribute.subattribute.subattribute2.finalattribute1 attribute.subattribute.subattribute2.finalattribute2 attribute.subattribute.subattribute2.finalattribute1 attribute.subattribute.subattribute2.finalattribute2

Is there a way in StringTemplate4 to store the subattribute2 in a "Variable" that I could then refer to instead to tidy up the logic somewhat?在 StringTemplate4 中有没有办法将 subattribute2 存储在一个“变量”中,然后我可以参考它来稍微整理一下逻辑?

Any help would be greatly appreciated :)任何帮助将不胜感激 :)

You could use a helper template:您可以使用辅助模板:

foo(attribute) ::= <<
<helper(attribute.subattribute.subattribute2)>
>>

helper(sub) ::= <<
<sub.finalattribute1>
<sub.finalattribute2>
>>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM