Version 2.2 by Manuel Smeria on 2013/01/24

Hide last authors
jeanvivienmaurice 1.11 1 You have to use Velocity macros. Here are the possible macros you can use to this purpose :
2
Manuel Smeria 2.1 3 {{toc start="" depth="" numbered=""/}}
jeanvivienmaurice 1.1 4
Manuel Smeria 2.1 5 {{html clean="false" wiki="true"}}
Manuel Smeria 2.2 6 = Include an <code>*.vm</code> script =
jeanvivienmaurice 1.1 7
jeanvivienmaurice 1.17 8 These macros take as parameter a relative URL to a <code>*.vm</code> script.
9
Manuel Smeria 2.2 10 == <code>template()</code> ==
jeanvivienmaurice 1.17 11
Manuel Smeria 2.1 12 {{info}}Specification : [[code:Macros.TemplateMacro]]{{/info}}
jeanvivienmaurice 1.1 13 This is the equivalent of the C preprocessor <code>include</code> directive : the result is a copy of the script passed as argument, into your script.
14
Manuel Smeria 2.2 15 = Include the Velocity code of another XWiki page : =
jeanvivienmaurice 1.17 16
Manuel Smeria 2.1 17 These macros take as parameter the XWiki name of a page, <Web>.<Page> .
jeanvivienmaurice 1.17 18
Manuel Smeria 2.2 19 == <code>includeInContext()</code> ==
Manuel Smeria 2.1 20
21 {{info}}Specification : [[code:Macros.IncludeInContextMacro]]{{/info}}
jeanvivienmaurice 1.13 22 If you have a script stored as an XWiki page, you can include its code into another script by using <code>includeInContext</code> :
23
Manuel Smeria 2.1 24 {{code}}#includeInContext("mySpace.myPage"){{/code}}
jeanvivienmaurice 1.1 25
Manuel Smeria 2.2 26 == <code>includeForm()</code> ==
Manuel Smeria 2.1 27
28 {{info}}Specification : [[code:Macros.IncludeFormMacro]]{{/info}}
jeanvivienmaurice 1.14 29 Similar to <code>includeInContext()</code>, except that using <code>includeForm()</code> in a page will set the default edit mode for that page as "inline".
jeanvivienmaurice 1.15 30 For example, the script you want to include uses the method <code>com.xpn.xwiki.doc.XWikiDocument.display()</code> to access a field of an object attached to the including page, like a typical class sheet :
Manuel Smeria 2.1 31
32 {{code language="velocity"}}
jeanvivienmaurice 1.1 33 ## Change class name to your class name
34 #set($class = $doc.getObject("CompanionTemplateSystem.CompanionDocumentMetaDataClass").xWikiClass)
35
36 <dl>
37 #foreach($prop in $class.properties)
38 #if(($prop.getName() != "Copyright") && ($prop.getName() != "TargetGroup") )
39 <dt> *${prop.prettyName}* </dt>
40 <dd>$doc.display($prop.getName())</dd>
41 #end
42 #end
43 </dl>
Manuel Smeria 2.1 44 {{/code}}
45
jeanvivienmaurice 1.15 46 which is stored as a regular XWiki page (let's say <code>myPage</code> in <code>mySpace</code>).
Manuel Smeria 2.1 47 <p/>
jeanvivienmaurice 1.15 48 You will include the page using <code>includeForm()</code> :
jeanvivienmaurice 1.1 49
Manuel Smeria 2.1 50 {{code}}#includeForm("mySpace.myPage"){{/code}}
51
jeanvivienmaurice 1.15 52 This way, the including page will always be edited in <code>inline</code> mode by default. Thus in the example of the class sheet, the including page will display input fields mapped to the respective object fields.
Manuel Smeria 2.1 53 <p/>
54 If you prefer to keep the default edit as set in your [[XWiki.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.
jeanvivienmaurice 1.1 55
Manuel Smeria 2.2 56 == <code>includeTopic()</code> ==
jeanvivienmaurice 1.14 57
Manuel Smeria 2.1 58 {{info}}Specification : [[code:Macros.IncludeTopicMacro]]{{/info}}
jeanvivienmaurice 1.13 59 Same syntax as <code>includeInContext()</code>. Contrary to <code>includeInContext()</code>, the included XWiki page is interpreted in its own context. For example, you would include a page using <code>includeTopic()</code> if the included page had to access its own objects in order for the including page to display properly.
Manuel Smeria 2.1 60 {{/html}}

Get Connected