0

I'm trying to render a tree structure using VLT, by indenting the rendering depending on the level it's on.

I tried to use a recursive macro which passes on the $indentLevel variable (see code below). However, instead of remembering the "original" $indentLevel, it just continues to increment. I thought that the foreach would fallback to the previous value upon its completion, but apparently not. Is there anyway I can make the $indentLevel variable local to a single loop?

Thanks

#macro(renderChildItems $item $indentLevel) #set($childItems = $transaction.workItems().search().query("linkedWorkItems:parent=$item.fields.id.get AND NOT status:obsolete AND type:(design_decision system_requirement)").sort("id")) #foreach($child in $childItems) <tr> <td style="padding-left:$indentLevel$px"> $child.render.withTitle.withLinks.openLinksInNewWindow() </td> </tr> #set($indentLevelNew = $indentLevels + $indentSizeInt) #renderChildItems($child $indentLevelNew) #end #end 

1 Answer 1

0

After some futher thoughts, I came to the conclusion that the answer is actually very simple: Just remove the increment after completion of the foreach loop:

#macro(renderChildItems $item $indentLevel) #set($childItems = $transaction.workItems().search().query("linkedWorkItems:parent=$item.fields.id.get AND NOT status:obsolete AND type:(design_decision system_requirement)").sort("id")) #foreach($child in $childItems) <tr> <td style="padding-left:$indentLevel$px"> $child.render.withTitle.withLinks.openLinksInNewWindow() </td> </tr> #set($indentLevelNew = $indentLevels + $indentSizeInt) #renderChildItems($child $indentLevelNew) #end #set($indentLevelNew = $indentLevels - $indentSizeInt) ##NEW #end 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.