简体   繁体   中英

StringTemplate4 - Storing attribute value in variable

I am injecting an attribute into my StringTemplate4 template which has multiple levels of sub-attributes.

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

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?

Any help would be greatly appreciated :)

You could use a helper template:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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