Velocity Macro

Last modified by Admin on 2024/04/12 12:07

cogExecutes a Velocity script and apply current page parser on the result
Developed by

XWiki Development Team

0 Votes
LicenseGNU Lesser General Public License 2.1
Bundled With

XWiki Standard

Installable with the Extension Manager


Executes Velocity on the content of the macro.


{{velocity filter="..." output="..." wiki="..."}}
...content here...

What's important to understand is that the Velocity engine will execute first on the content and then only, if wiki is true (which is the default) , the resulting content will be parsed using a wiki content parser.

Since Velocity executes first, if you put an {{include}} macro inside the {{velocity}} macro you will not be able to use any Velocity macro/variable defined in the included page because the include is done after Velocity is executed. Thus, take care of putting the {{include}} macro outside of  the {{Velocity}} macro or use the defined macro/variable in a separate {{velocity}} macro, as in:

## Note: The included page defines a $var variable in this example
{{include reference="somepage"/}}
## Note: Calling $var here won't work since it would be executed before the include is done


Parameters definition

Velocity macro extends Script Macro and support all its parameters (except the language selection which is always velocity).

Following are Velocity macro specific parameters:

NameOptionalAllowed valuesDefault valueDescription
filteryesnone/html/indentindentIndicate a filter to apply on velocity content before and after script execution. The default filter (indent) remove all first whites spaces of lines to support code indentation. See Velocity Macro Filter for more details.


#set($words = ["Some", "velocity", "code"])
#foreach($word in $words)
  $word ##


Some velocity code


Shows how to do some dynamic include.

#if (... some condition...)
 #set ($ref  = "page1")
 #set ($ref  = "page2")
{{include reference="$ref"/}}

This will include page1 or page2 depending on the condition.

XWiki Standard Velocity Macros


Velocity Macros (a.k.a Velocimacros) are a feature of the Velocity engine. XWiki provides several of them inside the macros.vm template file, that you can use in your wiki pages or template files.

per page of Page
The environment prevents the table from loading data.

Prerequisites & Installation Instructions

We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager).

You can also use the manual method which involves dropping the JAR file and all its dependencies into the WEB-INF/lib folder and restarting XWiki.


Dependencies for this extension (org.xwiki.platform:xwiki-platform-rendering-macro-velocity 16.2.0):

Get Connected