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

XWiki Development Team

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

XWiki Enterprise, XWiki Enterprise Manager

Installable with the Extension Manager

Description

Executes Velocity on the content of the macro.

Usage

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

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:

{{velocity}}
## 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
{{/velocity}}

{{velocity}}
$var
{{/velocity}}

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.

Example1

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

Result:

Some velocity code

Example2

Shows how to do some dynamic include.

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

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). Note that installing Extensions when being offline is currently not supported and you'd need to use some complex manual method.

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

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

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

Get Connected