String Conditionals

If True

The #if directive in Velocity allows for text to be included when the web page is generated, on the conditional that the if statement is true. For example:

Remember to use double equals == otherwise a velocity error will occur.

  1. #if($userName)  
  2.     Hello $userName  
  3. #end  

#elseIf / #else

The #if directive in Velocity allows for text to be included when the web page is generated, on the conditional that the if statement is true. For example:

  1. #if( $value < 10 )  
  2.     Go North  
  3. #elseif( $value == 10 )  
  4.     Go East  
  5. #elseif( $value == 6 )  
  6.     Go South  
  7. #else  
  8.     Go West  
  9. #end  

If this AND that

Here the double ampersands (&&) mean variable A and variable B must be set.

  1. #if($fruit == "apple" && $fruit=="pear")  
  2.     Hello World!  
  3. #end  

If this OR that

Here the double pipes (||) indicate either A or B must be set.

  1. #if($fruit == "apple" || $fruit=="pear")  
  2.     Hello World!  
  3. #end  
comments powered by Disqus