Wiki source code of Programming

Version 8.5 by Silvia Macovei on 2012/03/16

Show last authors
1 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>>http://velocity.apache.org]]** and **[[Groovy>>http://groovy.codehaus.org]]**.
2
3 XWiki exposes an API that allows you to manipulate the wiki and its documents easily.
4
5 To whet your appetite simply put the following code in your page:
6
7 {{code language="none"}}
8 {{velocity}}
9 #set($query = "where doc.parent is null or doc.parent='' order by doc.name asc")
10
11 #foreach($item in $xwiki.searchDocuments($query))
12 #set($lostdoc = $xwiki.getDocument($item))
13 * [[${lostdoc.web}.${lostdoc.name}>>${lostdoc.web}.${lostdoc.name}]]
14 #end
15 {{/velocity}}
16 {{/code}}
17
18 And you'll get a list of orphaned pages (i.e. pages that have no parent). For example:
19
20 {{image reference="velocityexampleresult.png"/}}
21
22 Another example of the programming features being used on XWiki.org is the **[[References page>>xwiki:References.WebHome]]**. On this page, data coming from individual pages is gathered and displayed.
23 * [[Velocity>>http://velocity.apache.org]] is used to take the first attachment of children pages and display it as a thumbnail on the [[References page>>xwiki:References.WebHome]]. When no attachment is available, a default thumbnail is displayed instead.
24 * [[Velocity>>http://velocity.apache.org]] is also used to retrieve and show specific bits of information (such as project names for instance).
25
26 **[[Check out how the page is coded>>http://www.xwiki.org/xwiki/bin/view/References/?viewer=code&]]** to find out more.
27
28 Check the **[[Developer's Guide>>DevGuide.WebHome]]** and especially the **[[XWiki Scripting section>>DevGuide.Scripting]]** to learn more.
29
30 You might also want to check out the **[[Extensions wiki>>extensions:Main.WebHome]]** which contains code snippets that you can reuse in your pages.

Get Connected