Search code examples
foreachvelocity

2 variable foreach loop in Velocity Template Language


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


Solution

  • 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