Purpose

While implementing that little piece of code in a page, you'll have a short glance over the combination between velocity language and XWiki API functions.

That piece of code allows you to display the last event created in calendar in an other page.

#set($document = $xwiki.getDocument("Main.EventCalendar"))
#foreach($event in $document.getObjects("XWiki.CalendarEvent"))

* $event.title
#end

This table below shows the repartition between the two languages.

VelocityXWiki API
#set$xwiki.getDocument
$document$document.getObjects
#foreachXWiki.CalendarEvent
$event 
$event.title 
#end 

For further information :

part 1

#set($document = $xwiki.getDocument("Main.EventCalendar"))

  • $document is created as well as it is declared.
  • $document will contain the document "EventCalendar" found in the "Main" space. That variable will contain as well as objects, content, rights, etc...
  • $xwiki before .getdocument means that the query is running over all the pages of the site. It assigns the context of the action.
  • .getdocument is a method belonging to the XWiki API. It gives access to the priviledged API of the Document.

part 2

#foreach($event in $document.getObjects("XWiki.CalendarEvent"))

  • This #foreach loop causes the $document list to be looped over for all of the events in the list. Each time through the loop, the value from $document is placed into the $event variable.

part 3

* $event.title
#end

  • $event contains the different properties of the object "CalendarEvent". Those properties are : title, startDate, endDate, Description, location, URL, categories, user. You may check here : .../edit/XWiki/CalendarEvent?editor=class
  • $event.title allows to display the title of the event.
  • #end closes the loop. If you forget it, you'll get an error message.
Version 1.1 last modified by StephaneBarbey on 06/03/2008 at 12:49

Comments 0

No comments for this document

Attachments 0

No attachments for this document

Creator: StephaneBarbey on 2008/03/06 12:48
This wiki is licensed under a Creative Commons license
1.5.2.12758