Moon
Moon

Reputation: 22565

How to add values to dynamic(?) map in velocity?

I have the following velocity code.

#foreach($content in $list)
   #set($map = {$content.categoryName:[]})

   #foreach($child in $children)
      // I want to add values to $map.$content.categoryName
   #end
#end

I would like to add values to $map.$content.categoryName. I tried

$map.$content.categoryName.add(values here) 

but it didn't work. I also tried

$map[$content.categoryName].add(values here)

But it still didn't work. Could someone please help me with this problem.

Upvotes: 0

Views: 1567

Answers (1)

Nathan Bubna
Nathan Bubna

Reputation: 6933

It's java, not javascript:

$map.get($content.categoryName).add($child.value)

Upvotes: 2

Related Questions