[
https://issues.apache.org/jira/browse/VELOCITY-619?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12636332#action_12636332
]
Byron Foster commented on VELOCITY-619:
---------------------------------------
My main motivation for this patch is to provide a need for this functionality
when running in strict mode VELOCITY-618 Mainly it would be good to allow the
developer to provide default values for variables that are referenced but not
defined in the template, without the need to add them to the context in java
code.
An alternative to this method would be to provide an exception in strict mode
in the case of #if($foo). In the case of just a single variable argument in
#if strict mode would not throw an exception in the case $foo is not defined,
and the #if would fail. so the following could be done (As it can be now).
#if ( ! $foo) #set($foo = "bar") #end
My only concern with this is that it is an exception, which means to me a
"special case" which often times leads to confusion in behavior. But perhaps
it's justified in this situation.
> New set modifier so that set only assigns a value when variable is not
> defined.
> -------------------------------------------------------------------------------
>
> Key: VELOCITY-619
> URL: https://issues.apache.org/jira/browse/VELOCITY-619
> Project: Velocity
> Issue Type: Improvement
> Components: Engine
> Reporter: Byron Foster
> Attachments: setBangModifier_2.patch
>
>
> Define a new #set modifier such that a variable is only set if it is not
> defined, like so:
> #set($!foo = "bar")
> If the '!' character proceeds the variable foo, then $foo will be set with
> the value of "bar" ONLY IF $foo is not defined (is not in the context).
> Otherwise if $foo is defined it will remain unchanged.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]