$null check in velocity

lucky picture lucky · Aug 13, 2010 · Viewed 72k times · Source

I came to know about null check using $null in velocity 1.6 through a resource updated by you. Resource: Reading model objects mapped in Velocity Templates But I am facing so many challenges that there is no $null for null check in velocity as there is no documentation provided about this. Please provide me with documentation stating $null as valid for null check in velocity.

Thanks in Advance lucky

Answer

a_horse_with_no_name picture a_horse_with_no_name · Aug 13, 2010

To check if a variable is not null simply use #if ($variable)

#if ($variable) 
 ... do stuff here if the variable is not null
#end

If you need to do stuff if the variable is null simply negate the test

#if (!$variable)
 ... do stuff here if the variable is null
#end