You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by "Christopher Schultz (JIRA)" <de...@velocity.apache.org> on 2010/09/18 02:35:32 UTC

[jira] Commented: (VELOCITY-773) Provide locally scoped #set variables

    [ https://issues.apache.org/jira/browse/VELOCITY-773?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12910874#action_12910874 ] 

Christopher Schultz commented on VELOCITY-773:
----------------------------------------------

What implications does this have for code like this:

#foreach($foo in $foos)
  #set($foreach.someVar = 'some value')
  #foreach($bar in $bars)
    .. terribly interesting stuff
  #end

  $foreach.someVar
#end

Does each foreach loop create a nested Context in which vars are defined and then cleared? Otherwise, the behavior of nested foreach loops might surprise some people.

> Provide locally scoped #set variables
> -------------------------------------
>
>                 Key: VELOCITY-773
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-773
>             Project: Velocity
>          Issue Type: Improvement
>          Components: Engine
>    Affects Versions: 1.7-beta1
>            Reporter: Michael Osipov
>
> Consider this snippet:
> <!-- Generated pushbutton groups -->
> #foreach ($group in $form.pushbuttonGroups)
> <div class="die-button-group" style="#coordinates($group)">
> #*	*##foreach ($groupChild in $group.children)
> #*		*##if (!$velocityHasNext)#set($turnPaddingOff = 'style="padding-bottom: 0px;"')#end
> #*		*##if ($groupChild.class.simpleName == "Pushbutton")
> 	#*	*#<div $!turnPaddingOff>
> 		#*	*#<button type="submit" name="$groupChild.name" value="$groupChild.value" onclick="loadSubsequent()">#label($groupChild.label)</button>
> 				
> 	#*	*#</div>
> #*		*##end
> #*	*##end
> </div>
> #end
> There is an inherent bug. After the first run of the outer foreach, the var turnPaddingOff is still available and will always set in the div tag. There is only one workaround. At the end of the outer foreach you have to set it to ''.
> #set should be available as a locally scoped thing in #foreach or other constructs.

-- 
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: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org