PerBonomi
11 years agoBoss
Loop through Freemarker variables?
I'm trying to loop through a list of Freemarker variables in javascript, but not having any luck. Is it possible?
Example. This works fine:
<#assign variable0 = "value0"/> <#assign variable1 = "value1"/> <#assign variable2 = "value2"/> <script> var arTest = new Array(); arTest[0] = '${variable0}'; arTest[1] = '${variable1}'; arTest[2] = '${variable2}'; </script>
But if I have a list of about 20+ variables, I'd really rather loop through. That, however, gives me a nasty error.
<#assign variable0 = "value0"/> <#assign variable1 = "value1"/> <#assign variable2 = "value2"/> <script> var arTest = new Array(); for (i=0; i < 3; i++) { arTest[i] = '${variable' + i + '}'; } </script>
Freemarker template 'preview' parsing failed:
ParseException:Parsing error in template "preview" in line 36, column 31: Encountered "\' + \'", but was expecting one of: "}" "." "[" "(" "?" "!" <TERMINATING_EXCLAM> "??" "+" "-" "*" "/" "%" "!=" "=" "==" ">=" <ESCAPED_GTE> ">" <ESCAPED_GT> <LESS_THAN_EQUALS> <LESS_THAN> ".." <AND> <OR>
Also, if I escape the variable the result is ${variable0} instead of value0.