Scripting

XWiki integrates both Velocity and Groovy scripting. Together, these two mechanisms allow you to create basic to complex web applications at the XWiki page (or view) layer without the need for compiling code or deploying software components. In other words, you can use Velocity and Groovy script syntax in addition to wiki and HTML syntax as the contents of an XWiki page.

XWiki's Velocity API

The concept of the 'context' is central to Velocity. The context is a 'carrier' of data between the Java layer of the XWiki engine and the template or page layer. The programmers of the XWiki core have gathered objects of various types and placed them in the Velocity context. These objects, and their methods and properties, are accessable via template elements called references and effectively form an API for XWiki.

The API is documented in Javadoc format and can be accessed here: XWiki API Javadoc. If you are not familiar with Java or object oriented programming, you will probably be confused by the API documentation. It is not within the scope of our documentation to teach you all the details about Velocity, Java, or object oriented programming. You can find all of that information already online. Instead, we provide only a high-level overview in Basic Velocity Scripting Tutorial; it will give you a good sense for how Velocity scripting works in XWiki. You should then refer to the Velocity User Guide as an ongoing reference. Finally, you can explore the page code found throughout the Code Zone area to see how others have figured out how to achieve a variety of results.

You can access in your velocity script to :

  • The current document: $doc
  • The Context of the request: $context
  • the request object: $request
  • the XWiki Object: $xwiki
You can also use HQL to query the XWiki database from your velocity scripts.

To include Velocity scripts in other Velocity scripts, see How to include a velocity page into another page.

XWiki's Groovy API

Currently Groovy is only allowed for admins of a wiki (or users having the 'programming' right).

Version 8.1 last modified by VincentMassol on 03/03/2008 at 10:28

Comments 3

brandone | 15.01.2007 at 02:20 PM
Guys, Also something I'm bumping into a lot lately is the need to use Math tools - searching on various topics (abs, math, div, add, etc) yields only one math topic which only shows multiplication and addition - but nothing else. Or, is the velocity math tool exposed to the user in some way?

snowedice | 03.07.2007 at 03:23 AM
From this page, it is totally confusing what role velocity or groovy play. It does not explain what the doc, xwiki,…

ricaforrica | 20.08.2007 at 02:19 PM
The link to Guillaume's interview is not working :) It is located in http://www.stelligent.com/content/view/44/71/ Regards!

Attachments 0

No attachments for this document

Creator: VincentMassol on 2006/12/05 14:05
This wiki is licensed under a Creative Commons license
1.4.1.10194