Reputation: 337
I've attached an object to an XWiki page. Now when the page is displayed, all the attributes of the object are displayed in the page too. I don't want to dispaly all the fields, how do I hide some of them?
Upvotes: 0
Views: 1189
Reputation: 3527
Short answer: if you want to modify how an object is displayed in an XWiki page, you can edit the class sheet for this.
Longer anser: Assume that the object if of class BarClass
in Space Foo
, or short in Foo.BarClass
. This class page, which defines what fields your objects have, has two accompanying pages, the class template at Foo.BarTemplate
, and a class sheet Foo.BarSheet
, which contains the code to display objects of this class. You want to look into the sheet.
This can be done by opening the page in the wiki editor, e.g.
http://localhost:8080/xwiki/bin/edit/Foo/BarSheet?editor=wiki
You will see a code like:
{{velocity}}
## You can modify this page to customize the presentation of your object.
## At first you should keep the default presentation and just save the document.
#set($class = $doc.getObject('Foo.BarClass').xWikiClass)
#foreach($prop in $class.properties)
; $prop.prettyName
: $doc.display($prop.getName())
#end
{{/velocity}}
If you want to hide, say field2
, you can do this by changing the foreach
loop to:
#foreach($prop in $class.properties)
#if ($prop.name != 'field2' || $xcontext.action == 'edit')
; $prop.prettyName
: $doc.display($prop.getName())
#end
#end
The $prop.name != 'field2'
makes sure the field is not shown if that field's name is field2
and the $xcontext.action == 'edit'
takes care that your field is still shown in the edit mode (otherwise your users will not be able to edit the field, which is probably not what you want).
If instead you have created your class with the AppWithinMinutes
, the class sheet looks differernt:
{{velocity}}
{{html wiki="true"}}
#set ($discard = $doc.use('FooBarCode.FooBarClass'))
#set ($discard = $services.localization.use('document', 'FooBarCode.FooBarTranslations'))
(% class="xform" %)
(((
; <label for="FooBarCode.FooBarClass_0_field1">$escapetool.xml($doc.displayPrettyName('field1', false, false))</label>
: $doc.display('field1')
; <label for="FooBarCode.FooBarClass_0_field2">$escapetool.xml($doc.displayPrettyName('field2', false, false))</label>
: $doc.display('field2')
; <label for="FooBarCode.FooBarClass_0_field3">$escapetool.xml($doc.displayPrettyName('field3', false, false))</label>
: $doc.display('field3')
)))
{{/html}}
{{/velocity}}
In that case you need to find the two lines displaying the field you want to hide, and wrap then into a simple #if ($xcontext.action == 'edit')
like:
#if ($xcontext.action == 'edit')
; <label for="FooBarCode.FooBarClass_0_field2">$escapetool.xml($doc.displayPrettyName('field2', false, false))</label>
: $doc.display('field2')
#end
If you want to know more about how XWiki classes are used, read the tutorial at http://platform.xwiki.org/xwiki/bin/view/DevGuide/FAQTutorialManual
Usually you want to create and manage your wiki classes via the "App within minutes" application: http://extensions.xwiki.org/xwiki/bin/view/Extension/App+Within+Minutes+Application which creates an user friendly interface, but for customizations like the one you wanted, you need to edit the sheet directly.
Upvotes: 1