How to include a velocity page into another page ?
You have to use Velocity macros. Here are the possible macros you can use to this purpose :Include an *.vm script
These macros take as parameter a relative URL to a *.vm script.
template()
This is the equivalent of the C preprocessor include directive : the result is a copy of the script passed as argument, into your script.
Include the Velocity code of another XWiki page :
These macros take as parameter the XWiki name of a page, <Web>.<Page> .includeInContext()
If you have a script stored as an XWiki page, you can include its code into another script by using includeInContext :
#includeInContext("mySpace.myPage")includeForm()
Similar to includeInContext(), except that using includeForm() in a page will set the default edit mode for that page as "inline".
For example, the script you want to include uses the method com.xpn.xwiki.doc.XWikiDocument.display() to access a field of an object attached to the including page, like a typical class sheet :
## Change class name to your class name #set($class = $doc.getObject("CompanionTemplateSystem.CompanionDocumentMetaDataClass").xWikiClass) <dl> #foreach($prop in $class.properties) #if(($prop.getName() != "Copyright") && ($prop.getName() != "TargetGroup") ) <dt> *${prop.prettyName}* </dt> <dd>$doc.display($prop.getName())</dd> #end #end </dl>
myPage in mySpace).
You will include the page using includeForm() :
#includeForm("mySpace.myPage")inline mode by default. Thus in the example of the class sheet, the including page will display input fields mapped to the respective object fields.
If you prefer to keep the default edit as set in your XWiki Preferences class, you can use the other macros, and still edit a page in inline mode : choose the "Inline form" option in the "Edit" menu, provided you have enabled "Advanced Edit" in your user profile.
includeTopic()
Same syntax as includeInContext(). Contrary to includeInContext(), the included XWiki page is interpreted in its own context. For example, you would include a page using includeTopic() if the included page had to access its own objects in order for the including page to display properly.
Version 1.22 last modified by VincentMassol on 10/12/2007 at 18:07
Document data
Attachments:
No attachments for this document
Comments: 6