1

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 :)

John Bartlett
  • 370
  • 1
  • 3
  • 13

1 Answers1

0

You could use a helper template:

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

helper(sub) ::= <<
<sub.finalattribute1>
<sub.finalattribute2>
>>
Clashsoft
  • 11,553
  • 5
  • 40
  • 79