0

Is there any way to use 2 variables in foreach loop ?

#foreach( $name in $names &&  $method in $methods )
$name  : $method
#end

Because I want to print the result side by side

Claude Brisson
  • 4,085
  • 1
  • 22
  • 30

2 Answers2

0

Just loop over an index.

Assuming both collections have the same size:

#set($size = $names.size - 1)
#foreach( $i in [0..$size])
  $names[$i] : $methods[$i]
#end

(edited for correctness)

Claude Brisson
  • 4,085
  • 1
  • 22
  • 30
0

I found the solution, just put in the Map

Map<String, String> maps = new HashMap<>();

ctx.put("rows",  maps);

and iterate over key in maps

#foreach( $key in $rows.keySet() )
 Key: $key  Value: $rows.get($key)
#end