Do you really mean two different contexts? just two different
lists/collections/arrays, found in your context? Btw, I've always
thought the ability to do something like:
#foreach( $user in $users, $food in $foods )
$user likes $food!
#end
would be incredibly convenient. Kinda wished Java 5 would have added
this ability but instead we just got the same crippled foreach everyone
else has. :-)
Anyway, Tarun, you were close with your original workaround:
<option value="$context2[$counter]">$ctx1</option>
except that there's no syntax for array access, so it will just print
out the full contents of your second list and then follow it with [#]
each time. What you want to try instead is:
<option value="$context2.get($counter)">$ctx1</option>
make sure that $counter is one less than the $velocityCount
automatic variable or you'll get an index out of bounds exception.
Tarun wrote:
>Thanks Avinash for replying
>but i am not using the velocity framework. i am using the turbine framework
>with velocity as a view template only. i have stucked in this problem . is
>there any method in which a single foreach loop i can iterate two contexts.
>
>like this #foreach($ctx1 in context1 , $ctx2 in context2) obviously this is
>not working. but like that is there any other way.
>
Message
>From: "avanish" <avanish.awasthi (AT) secf (DOT) com>
>To: "Velocity Users List" <velocity-user (AT) jakarta (DOT) apache.org>
>Sent: Thursday, June 23, 2005 8:51 AM
>Subject: Re: How to iterate the two different context in a single foreach
>loop
>
>
>
>>Why r u using two different contexts ?
>>Also this problem can be solved it we do context chaining
>>
>Message
>>From: "Tarun" <tarun.narang (AT) secf (DOT) com>
>>To: "Velocity Users List" <velocity-user (AT) jakarta (DOT) apache.org>
>>Sent: Wednesday, June 22, 2005 5:35 PM
>>Subject: How to iterate the two different context in a single foreach loop
>>
>>
>>hii
>>I am new to velocity
>>i am getting two context on the velocity template say
>>context1 and context2. Both these contexts have an array of string and of
>>same length.
>>Now in a single loop i want to iterate the values of both the context. But
>
>>
>i
>
>>am not able to do that.
>>what i was trying to do is that:-
set($counter = 0)
>>
foreach($ctx1 in $context1)
>>
>><select name="combobox">
>>
>><option value="$context2[$counter]">$ctx1</option>
>>
>></select>
>>
end
>>
>>Here in the foreach loop $ctx1 is returning me the exact values but the
>>$context2[$counter] is returning me the object of the array string.
>>
>>so i am not able to get the values. So is there any way in which i can
>>iterate the two context in a single foreach loop or any another way you
>
>>
>can
>
>>suggest.
>>
>>Thanks in Advance
>>
>>Tarun
>>
>>
>>
>>
>>
>>
>>To unsubscribe, e-mail: velocity-user-unsubscribe (AT) jakarta (DOT) apache.org
>>For additional commands, e-mail: velocity-user-help (AT) jakarta (DOT) apache.org
>>
>>
>
>>
>
>
>
>
>
>To unsubscribe, e-mail: velocity-user-unsubscribe (AT) jakarta (DOT) apache.org
>For additional commands, e-mail: velocity-user-help (AT) jakarta (DOT) apache.org
>
To unsubscribe, e-mail: velocity-user-unsubscribe (AT) jakarta (DOT) apache.org
For additional commands, e-mail: velocity-user-help (AT) jakarta (DOT) apache.org