how to not call a macro if the varialbe is null?

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

how to not call a macro if the varialbe is null?

graild
I am calling a macro like this:

<@u.listUsers users variable2 variabe3 />


And inside of listUsers.ftl I have:

..
..

 <@v.someThing varaible2 />


Now say variable2 is null, is it possible to do soething like:

if variable2 != null
{
   <@v.someThing variable2 />
}


meaning, don't call this macro if the varialbe is null.



------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT
organizations don't have a clear picture of how application performance
affects their revenue. With AppDynamics, you get 100% visibility into your
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&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: how to not call a macro if the varialbe is null?

graild
Also in the call to:

<@u.listUsers users variable2 variable3 />

I want to make variable2 nullable, is that possible or it has to be a required param?


On Fri, Dec 27, 2013 at 5:34 PM, S Ahmed <[hidden email]> wrote:
I am calling a macro like this:

<@u.listUsers users variable2 variabe3 />


And inside of listUsers.ftl I have:

..
..

 <@v.someThing varaible2 />


Now say variable2 is null, is it possible to do soething like:

if variable2 != null
{
   <@v.someThing variable2 />
}


meaning, don't call this macro if the varialbe is null.




------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT
organizations don't have a clear picture of how application performance
affects their revenue. With AppDynamics, you get 100% visibility into your
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&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: how to not call a macro if the varialbe is null?

Sushrut Bidwai
In reply to this post by graild
You can selectively call a macro. 

<#if var2??>
  <@v.someThing variable2 />
</#if>

?? - Is the operator to check if the variable is null or not.



On Sat, Dec 28, 2013 at 4:04 AM, S Ahmed <[hidden email]> wrote:
I am calling a macro like this:

<@u.listUsers users variable2 variabe3 />


And inside of listUsers.ftl I have:

..
..

 <@v.someThing varaible2 />


Now say variable2 is null, is it possible to do soething like:

if variable2 != null
{
   <@v.someThing variable2 />
}


meaning, don't call this macro if the varialbe is null.



------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT
organizations don't have a clear picture of how application performance
affects their revenue. With AppDynamics, you get 100% visibility into your
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user




--
Best Regards,
Sushrut

------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT
organizations don't have a clear picture of how application performance
affects their revenue. With AppDynamics, you get 100% visibility into your
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&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: how to not call a macro if the varialbe is null?

Daniel Dekany
In reply to this post by graild
There's no null concept in FTL 2.3; it's the same as "undefined" for
it. As such, you can use a the existence operators to handle nulls.
<#if variable??>, or if you want to provide a default instead (say, 0,
but it can be anything), <@u.someThing variable2!0 />.

As of the second question, macro parameters can have a default value:
<#macro listUsers users arg2=someExpressionHere arg3>

--
Thanks,
 Daniel Dekany


Friday, December 27, 2013, 11:35:22 PM, S Ahmed wrote:

> Also in the call to:
>
> <@u.listUsers users variable2 variable3 />
>
> I want to make variable2 nullable, is that possible or it has to be a required param?
>
>
> On Fri, Dec 27, 2013 at 5:34 PM, S Ahmed <[hidden email]> wrote:
> I am calling a macro like this:
>
> <@u.listUsers users variable2 variabe3 />
>
>
> And inside of listUsers.ftl I have:
>
> ..
> ..
>
>  <@v.someThing varaible2 />
>
>
> Now say variable2 is null, is it possible to do soething like:
>
> if variable2 != null
> {
>    <@v.someThing variable2 />
> }
>
>
> meaning, don't call this macro if the varialbe is null.
>
>
>


------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT
organizations don't have a clear picture of how application performance
affects their revenue. With AppDynamics, you get 100% visibility into your
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user