How to assign a variable to an evaluated string

Rebecca Younes <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <C80DBAC4.DF9%[email protected]>
Consider this template code:


<#assign useOranges=false>
<#assign fruit>
    apples,
    bananas,
    <#if useOranges>
        oranges
    </#if>
</#assign>
<#assign arr=fruit?split(",")>
${arr?size}<br />
${fruit}


This outputs:
3
apples, bananas,

What I want is for ${arr?size} to print 2 rather than 3: i.e., for the contents of fruit to be evaluated before assigning it to arr. I've tried adding:

<#assign fruit2>${fruit}</#assign>
<#assign arr=fruit2?split(",")>

I also tried the eval built-in:

<#assign fruit2>${fruit?eval}</#assign>
<#assign arr=fruit2?split(",")>

Neither of these produce the desired output. Is there a way to do this in FreeMarker?

------------------------------------------------------------------------------

_______________________________________________
FreeMarker-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.