Martin Muzatko
Martin Muzatko

Reputation: 326

Velocity - Loop through properties of placeholders

I want to loop through a list of properties provided by a placeholder.

#foreach( $property in $placeholder )
    $property
#end

Is there any possible way to access them in my template?

Thanks in advance!

Upvotes: 1

Views: 1860

Answers (1)

Claude Brisson
Claude Brisson

Reputation: 4130

It depends upon your $placeholder object.

If it's a java.util.Map, you're free to iterate its keys, values or both:

#foreach($key in $placeholder.keySet())
  property $key is $placeholder[$key]
#end

#foreach($value in $placeholder.values())
  found value $value
#end

#foreach($entry in $placeholder.entrySet())
  property $entry.key is $entry.value
#end

If it's an array or a list, the syntax you've given would work.

Remember that you can call any java public method on your object. If you're unsure about its class, you can display it with $placeholder.class.name.

Upvotes: 3

Related Questions