0

I want to write the following if - else logic in Velocity

If $var1 == NONE
   ( If $subvar1 != 'null' 
      return True 
    else 
        return Failed_Sub1)
Else
    If $subvar2 != 'null' 
        return True 
     else 
        return Failed_Sub2

So basically $subvar2 is only evaluated if $var != NONE and $subvar1 is only evaluated if $var == NONE

I tried something like

#if($var1 != 'NONE')
    #if($subvar2 != 'null')True
    #{else}Failed_Sub2
    #end
#else
    #if($subvar1 != 'null')True
    #{else}Failed_Sub1
    #end
#end

But its returning nothing to me. What am I doing wrong?

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
Chris T
  • 155
  • 1
  • 11

1 Answers1

0

Do you want to avoid null values or strings containing 'null'?

In velocity, you can check for nulls using any non assigned reference, for instance $null :

#if($var1 == $null)
...

Otherwise than that, your code looks fine and nested #if statements are definitely possible.

Here's the relevant documentation.

Claude Brisson
  • 4,085
  • 1
  • 22
  • 30