1

I was doing some brief reading about Velocity template syntax. Specifically I am trying to create content which is rendered conditionally by the template engine. To be even more specific, I want to check a users permission groups in a Confluence instance, return an array of group names, then render the content conditionally (menu items for example) based on what they need to have access to with their current permission levels.

I was reading there is no "#break" directive, which seems ludicrous to me, so I set about testing the use of "#break" within my template code. What I ended up with is this:

#foreach ($group in $groupList)
#if (
$group == "administrators" ||
    $group == "group-1" ||
    $group == "group-2" ||
    $group == "group-3" ||
    $group == "group-4" ||
    $group == "group-5" ||
    $group == "group-6" 
)

<a href='<redacted link>'><li data-balloon-length="fit" data-balloon="View 
your agreements with us, e.g. your customer agreement, or our SLA's" data- 
balloon-pos="down">
<i class="fas fa-shower"></i>
<p>
  Hygiene
</p>
</li></a>
#break
#else
<a href='<redacted link>'><li class="no-permissions" data-balloon-length="fit" 
data-balloon="You have insufficient privileges to view this page" data- 
balloon-pos="down">
<i class="fas fa-shower"></i>
<p>
  Hygiene
</p>
</li></a>
#break
#end
#end

I'm extremely new to Velocity templates, as recent as a couple of months of practice. I see some huge advantages to be able to render the content conditionally, rather than, for example, post-processing with JS or jQuery for example.

My question is this, am I doing this correctly? Because from what I read, #break doesn't exist (perhaps old documentation I found, not sure).

Furthermore, a direct question, does the #break directive exist in Apache Velocity templates?

I would like to point out, this code works with minimal testing, any group is correctly recognised is no particular order, and it will only render one list item, or the other, regardless of the order of the groups.

Sorry for the dissertation of a question! And thanks in advance for your input.

Swift
  • 1,663
  • 1
  • 10
  • 21

1 Answers1

1

The #break directive has been introduced in Velocity 1.6.

It's easy to check the documentations for the different versions.

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