Velocity Macro
Executes a Velocity script and apply current page parser on the result |
Type | JAR |
Category | |
Developed by | |
Rating | |
License | GNU Lesser General Public License 2.1 |
Bundled With | XWiki Standard |
Table of contents
Description
Executes Velocity on the content of the macro.
Usage
...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.
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:
Name | Optional | Allowed values | Default value | Description |
---|---|---|---|---|
filter | yes | none/html/indent | indent | Indicate 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
#set($words = ["Some", "velocity", "code"])
#foreach($word in $words)
$word ##
#end
{{/velocity}}
Result:
Example2
Shows how to do some dynamic include.
#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.
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.10.1):
- org.xwiki.platform:xwiki-platform-rendering-macro-script 16.10.1
- org.xwiki.commons:xwiki-commons-velocity 16.10.1
- org.xwiki.rendering:xwiki-rendering-api 16.10.1
- org.xwiki.rendering:xwiki-rendering-transformation-macro 16.10.1