Re: How to assign a variable to an evaluated string
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Don't put a "," after the last item... it looks odd anyway. But if you
absolutely have to, after splitting remove the last element if it's an
empty string.
See:
http://freemarker.org/docs/ref_builtins_sequence.html#ref_builtin_last
http://freemarker.org/docs/dgui_template_exp.html#dgui_template_exp_seqenceop_slice
Monday, May 10, 2010, 7:29:40 PM, Rebecca Younes wrote:
> 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?
--
Best regards,
Daniel Dekany
------------------------------------------------------------------------------