Re: How to assign a variable to an evaluated string
"Daniels, Troy (US SSA)" <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
________________________________ From: Rebecca Younes [mailto:[email protected]] Sent: Monday, May 10, 2010 1:30 PM To: [email protected] Subject: [FreeMarker-user] How to assign a variable to an evaluated string Consider this template code: <#assign useOranges=false> <#assign fruit> apples, bananas, <#if useOranges> oranges </#if> </#assign> <#assign arr=fruit?split(",")> ${arr?size}<br /> ${fruit} Your second comma is outside the #if, so I think you will always get three elements, although the last one might be empty. Have you tried <#assign fruit> apples, bananas <#if useOranges> , oranges </#if> </#assign> which wyould give you apples, bananas without the trailing comma. Troy 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