can Velocity set a default value for a variable when no value found in VelocityContext?

后端 未结 6 1357
野的像风
野的像风 2021-01-18 08:45

Velocity just print the tag name if no value was found in VelocityContext, ie, $name in my template file, but there is no value for \"name\" in VelocityContext, so just \"$n

6条回答
  •  南方客
    南方客 (楼主)
    2021-01-18 09:05

    Not easily for all variables as far as I see, I only managed to do it for some variables specifically as follows:

    Template:

    #if ( !$somevar )
    #set ( $somevar = "mycontent" )
    #end
    
    Var is: $somevar
    

    Result:

    Var is: mycontent
    

提交回复
热议问题