Search code examples
variablesvelocitytemplate-engine

Velocity: Is a any way to check if variable is defined


I want to include one template nested into others cont1, cont2, cont3. And nested template should be hide one specific control for cont1 only. Before inclusion into cont1 I would like to assign value to some flag variable $hideMyControl.

And inside nested template I would like to check if $hideMyControl is assigned value.

How to perform such check?


Solution

  • You can do this using

      #if($!{$articleLeader})
          // Perform your operation or the template part you want to show.
      #end
    

    For more info, see the 'formal reference' section of the Apache Velocity Reference Manual.