Velocity Macro

Last modified by Admin on 2024/03/19 01:16

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

XWiki Development Team

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1
Bundled With

XWiki Standard

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.

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
Actions
The environment prevents the table from loading data.
 
Page

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

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

    

Get Connected