Forum Discussion
NicoB
12 years agoLithium Alumni (Retired)
Hi PerBonomi
What you're trying to do is impossible because Javascript is running when the page has already been rendered by Freemarker.
I would change your implementation with something similar:
<script>
<#assign bound = 3 />
var arr = new Array(${bound}); //3 here must match the higher bound below.
<#list 1..bound as curr>
arr[${curr}] = ${("variable" + curr)?eval}
</#list>
</script>
So, basically.. given bound the max number used for variableX (still wondering why you're not using a sequence anyway) I'm setting an element in the array using the Freemarker eval function which evaluate a string as Freemarker code (see here http://freemarker.org/docs/ref_builtins_expert.html#ref_builtin_eval)
I'm not sure this code works because I haven't tested it but this could trigger some idea maybe?
Edited: Reading the above Freemarker guide page I found that there's the interpret function which could also be helpful.
Thanks
Nico