Context Macro

Version 4.1 by Thomas Mortagne on 2011/10/27 19:24

cogExecutes content with another document set as the current document
Typejavamacro
Category
Developed byUnknown
Rating
0 Votes
LicenseGNU Lesser General Public License 2.1

Description

Useful when you need to get content from other documents displayed in the current document but using the other document as the base for resolving links and images. See the example below for some ideas on how to use it.

The Include Macro also provides a similar feature.

Usage

{{context document="wiki:space.page"}}
... content in wiki syntax here...
{{/context}}

Example 1

The following will display the link as a link to the Main.OtherPage document whereas without the context macro it would display a link to Main.Page.

{{context document="Main.OtherPage"}}
[[]]
{{/context}}

Example 2

Imagine you have an XWiki Object located in a Main.OtherPage document and that Object has an Icon field using the format attach:image.png. Imagine also that Main.OtherPage is using velocity scripting to extract the icon field and to display it on the page. This would fine since image.png would be a file attached to the page. Now imagine that in Main.Page we'd also want to display that icon. Since it's not defined in an absolute manner (that would be attach:[email protected]) it would fail to be displayed unless we used:

{{context document="Main.OtherPage"}}
{{velocity}}
image:$icon
{{/velocity}}
{{/context}}
Tags:
    

Get Connected