Programming

Version 1.21 by Vincent Massol on 2007/09/25

Programming

Bored of simple text in your pages? Are you interested in giving life to your wiki? Then you can make use of XWiki's powerful programming API directly from your wiki pages. XWiki offers 2 scripting languages: Velocity and Groovy.

XWiki exposes an API that allows you to manipulate the wiki and its documents easily.

To wet your appetite simply put the following code in your page:

#set($query = "where doc.parent is null or doc.parent='' order by doc.name asc")

#foreach($item in $xwiki.searchDocuments($query))
  #set($lostdoc = $xwiki.getDocument($item))
   * [${lostdoc.web}.${lostdoc.name}>${lostdoc.web}.${lostdoc.name}]
#end

And you'll get a list of orphaned pages (i.e. pages that have no parent). For example:

velocityexampleresult.png

Another example of the programming feature being used on XWiki.org is the References page. On this page, data coming from individual pages is gathered and displayed. Velocity is used to take the first attachment of children pages and display it as a thumbnail on the References page. When no attachment is available, a default thumbnail is displayed instead. Velocity is also used to retrieve and show specific bits of information (such as project names for instance). Check out how the page is coded to find out more.

Check the Developer's Guide and especially the XWiki Scripting section to learn more. You might also want to check out the Code Zone which contains code snippets that you can reuse in your pages.

Get Connected