Velocity
Apache Velocity is a server-side templating language used in Confluence to render page content. It enables integration of Java objects within standard HTML, making it a powerful tool for user macros.
Key Characteristics
Designed to dynamically generate content by combining static text with variable references, directives, and expressions.
Highly flexible, allowing developers to integrate it with various data sources and Java objects. It supports custom tools, macros, and user-defined directives.
Syntax Basics
Below are some common Velocity syntax elements used in Confluence:
Element | Syntax | Example |
|---|---|---|
Variable reference |
| $foo |
Variable assignment |
| #set ($message = "Hello") |
Conditional statements |
| #if ($message == "Hello") Message is Hello #end |
Loops |
| #foreach ($user in $users) $user <br> #end #foreach ($item in $items) #if ($item == "stop") #break ##if ($error) rror) #stop #end |
Quiet notation |
| #set($name = "Kevin") Hello, $name! ## Output: Hello, Kevin! Hello, $unknown! ## Output: Hello, $unknown! Hello, $!unknown! ## Output: Hello, ! (avoids rendering the output literally) |
To learn more about Velocity, please see the Velocity user guide.