Check if value is defined, then use it in if statement

9 views
Skip to first unread message

Harshdeep S Jawanda

unread,
Jun 27, 2014, 4:17:53 AM6/27/14
to Rythm Engine
What's the best/correct way to check (in template code) if the value for a particular variable has been defined (in the passed-in list of parameters), and if it has been defined then take either ActionA or ActionB based on that value?

For example, I want to write the equivalent of this pseudo-code:
if (variableZ.isDefined()) {
    if (variableZ) {
        ActionA;
    } else {
        ActionB;
    }
}
For simplicity I am assuming that variableZ is a boolean.

--
Regards,
Harshdeep S Jawanda

green

unread,
Jun 27, 2014, 5:16:36 AM6/27/14
to Rythm Engine
There is no argument can be undefined. Even if you didn't pass them in the params. Let's say you have `@args boolean b`, if you failed to pass value for argument `b`, then it will be in `false` the default value. If your argument is type Object, then the default value is null.

So your case could be simplified as:

@if(variableZ) {
   ActionA
} else {
   ActionB
}

Please refer more about variable evaluation at http://rythmengine.org/doc/directive.md#if


--
You received this message because you are subscribed to the Google Groups "rythmengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rythmengine...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages