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