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

XWiki Development Team

Active Installs0
0 Votes
LicenseGNU Lesser General Public License 2.1
Bundled With

XWiki Enterprise, XWiki Enterprise Manager

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.

Tested on

This extension has been tested with the following configurations.

Extension VersionXWiki FlavorNotes
6.1XWiki Enterprise 6.1

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.


Created by Thomas Mortagne on 2008/09/30 12:57

Get Connected