Short form of if..else

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Short form of if..else

anjibman
Hi All,

What is the short form of
<#if myDTO.field??>
   ${myDTO.filed?size}
<#else>
   0
<#/if>

Right now I have ${myDTO.field ! "0"} which doesn't print size if myDTO.field is not NULL.

 
Reply | Threaded
Open this post in threaded view
|

Re: Short form of if..else

Denis Bredelet
> Hi All,
>
> What is the short form of
> <#if myDTO.field??>
>   ${myDTO.filed?size}
> <#else>
>   0
> <#/if>
>
> Right now I have ${myDTO.field ! "0"} which *doesn't* print size if
> myDTO.field is not NULL.

Do you mean you have ${myDTO.field?size ! 0} ?


-- Denis.

------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Reply | Threaded
Open this post in threaded view
|

Re: Short form of if..else

Daniel Dekany
In reply to this post by anjibman
Tuesday, August 6, 2013, 10:56:44 PM, anjibman wrote:

> Hi All,
>
> What is the short form of
> <#if myDTO.field??>
>    ${myDTO.filed?size}
> <#else>
>    0
> <#/if>
>
> Right now I have ${myDTO.field ! "0"} which *doesn't* print size if
> myDTO.field is not NULL.

What your code really want to say is that if `field` doesn't exist,
then it should be treated like if its size was 0. So just say that in
FTL too:

  ${(myDTO.field![])?size}

Another solution is:

  ${(myDTO.field?size)!0}

but it's less telling, also it will hide the error if `myDTO` is null,
which is unintended.

--
Thanks,
 Daniel Dekany


------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user