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
| Velocity | XWiki API |
|---|---|
| #set | $xwiki.getDocument |
| $document | $document.getObjects |
| #foreach | XWiki.CalendarEvent |
| $event | |
| $event.title | |
| #end |
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
Document data
Attachments:
No attachments for this document
Comments: 0