Groovy Macro

Last modified by Admin on 2024/12/16 00:14

cogAdds ability to write scripts in Groovy in wiki pages
TypeJAR
Category
Developed by

XWiki Development Team

Active Installs5
Rating
0 Votes
LicenseGNU Lesser General Public License 2.1
Bundled With

XWiki Standard

Installable with the Extension Manager

Description

This is a shortcut for Script Macro equivalent to {{script language="groovy"}} to execute groovy scripts.

Usage

{{groovy}}
def list = ["one", "two"]
list.each { item ->
  println "* ${item}"
}
{{/groovy}}

Parameters definition

If Groovy script is not supposed to produce any output, for example, Groovy Class with just parameters is defined, declare  macro as:

{{groovy output="false"}}

See Script Macro for details.

Example

{{groovy}}
def list = ["one", "two"]
list.each { item ->
  println "* ${item}"
}
{{/groovy}}

Result

  • one
  • two

Note that since context is a reserved binding in JSR-223 specifications used for Scripting Macros, the XWiki Api Context is now accessible throught xcontext

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-groovy 16.10.1):

Get Connected