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 :

Invalid macro parameters used for the [toc] macro. Cause: [Failed to validate bean: [must be greater than or equal to 1]]. Click on this message for details.

Include an *.vm script

These macros take as parameter a relative URL to a *.vm script.

template()

Specification : TemplateMacro 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, . .

includeInContext()

Specification : IncludeInContextMacro 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()

Specification : IncludeFormMacro 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>
which is stored as a regular XWiki page (let's say myPage in mySpace).

You will include the page using includeForm() :

#includeForm("mySpace.myPage")
This way, the including page will always be edited in 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 XWikiPreferences 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()

Specification : IncludeTopicMacro 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.
Tags:
   

Get Connected