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

Nathan Bubna commented on VELOCITY-696:
---------------------------------------

Ok, we've established that i think this is ugly syntactically. :)   I haven't 
decided to veto it yet, though i have other complaints.  One is that it feels 
incomplete; what about $velocityHasNext?  Are you willing/able to push it to 
also support #foreach( $user in $users hasNext $hN ) and #foreach( $user in 
$users index $i hasNext $hN )?   The other is that we (or i, at least) already 
support another ugly (but more extensible) solution that handles both the index 
and hasNext cases:  LoopTool.  Moving this functionality to an optional #for 
directive doesn't feel like a good solution either.  Having a two ways to skin 
a cat is not simpler than having one way.  Again, it's more to learn and more 
to decide.  Currently a 2.0 user can handle an index-sensitive #foreach via:

#foreach and the default $velocityCount
#foreach and a configured $indexref
#foreach and LoopTool
#for and a specified index var
#for and the default $velocityCount
#for and a configured $indexref
#for and a specified index $indexref
#for and LoopTool

That's without even mentioning $velocityHasNext and the index start value.  Not 
simple, not good.  I think, if we want to support specifying the index variable 
in the #foreach args, then we should just do it in #foreach, not an optional 
directive.  It should also support hasNext to be consistent.  And, we should 
remove the ability to configure the default names (velocityCount and 
velocityHasNext), as that would no longer be necessary.   Either that, or we 
leave the configuration options, don't add the argument syntax and encourage 
people to use LoopTool if they need more advanced stuff.  Either way, we keep 
the list above to just three options and no limitations.

> Add index parameter to #foreach directive to define an index variable
> ---------------------------------------------------------------------
>
>                 Key: VELOCITY-696
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-696
>             Project: Velocity
>          Issue Type: Improvement
>          Components: Engine
>    Affects Versions: 2.0
>            Reporter: Byron Foster
>
> Allow the following:
> #foreach($user in $users index $i)
> #end
> So that $i holds the current index number of the iteration.  This is similar 
> in functionality to the implicitly defined index variable, except this is 
> more explicit.

-- 
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]

Reply via email to