You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Stan Devyatovsky <st...@devyatovsky.com> on 2004/05/07 22:38:42 UTC

Re[2]: default value?

Hello Nathan,

 Thanks everyone for your kind advices, that's what I needed.

>> I'm migrating from PHP/Smarty to Java/Velocity, and the question is
>> how can I conveniently use default value if my template variable is
>> not defined?
NB> i typically create a global velocimacro to handle this:
NB> #macro( altnull $value $alternate )##
NB> ## robust null checking (treats false booleans as non-null)
NB> #if ( "$!value" != "" )${value}#else${alternate}#end##
NB> #end
NB> then you can just do #altnull( $title "This Is A Web Site!" )

-- 
Best regards,
 Stan                            mailto:stan@devyatovsky.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org