Search code examples
javastringtemplate

Expression not working in stringTemplate


Hi I'm using StringTemplate version 3.2.1 and Java.

I'm passing in an ArrayList to the Stringtemplate but its not picking it up. I want to iterate through the array depending on the number of values.

ArrayList<Integer> test = new ArrayList<Integer>();

test.add(12334435);
test.add(12334436);
...
StringTemplate sysProperties = new StringTemplateGroup("group","locationOfTemplate").getInstanceOf("templateName");
sysProperties.setAttribute("system", "test");

(This will work)

sysProperties.setAttribute("n", test);

(But it seems to ignore the arrayList that is passed in. So depending on the number of values in the array, i want to dynamically build the xml)

StringTemplate on file:

<data>
$if(test)$
$test:{ n |
<value>
<string>$n$</string>
</value>}$
$endif$
</data>

Any help with this would be greatly appreciated. Thanks in advance.


Solution

  • It seems you're using ST4 syntax in ST3

    $test:{ **n|**<-- You should use 'it' attribute to iterate - "The iterated it atribute is
    set automatically" 
    

    source