Confluence 2.5.6 : Web UI Plugins
This page last changed on Aug 04, 2007 by brendan.patterson@gmail.com.
Web UI plugin modules allow you to insert links, tabs and sections of links into the Confluence web interface . They're not much use on their own, but when combined with XWork-WebWork Plugins they become a powerful way to add functionality to Confluence.
Sections and ItemsWeb UI plugins can consist of two kinds of plugin modules:
Web items or web sections (referred to collectively as 'web fragments') may be displayed in a number of different ways, depending on the location of the fragment and the theme under which it is being displayed. LocationsIn a number of places in the Confluence UI, there are lists of links representing operations relevant to the content being viewed. These are the locations that you can customise:
Web Item DefinitionHere's a sample atlassian-plugin.xml fragment for a web item: <web-item key="spacelogo" name="Space Logo" section="system.space.admin/looknfeel" weight="40"> <label key="configure.space.logo" /> <link>/spaces/configurespacelogo.action?key=$helper.spaceKey</link> <icon height="16" width="16"> <link>/images/icons/logo_add_16.gif</link> </icon> <condition class="com.atlassian.confluence.plugin.descriptor.web.conditions.NotPersonalSpaceCondition"/> </web-item>
Label elementsLabel elements may contain optional parameters, as shown below: <label key="navlink.attachments"> <param name="param0">$!helper.page.title</param> <param name="param1">$!helper.numberOfAttachments</param> </label>
Link elementsLink elements may contain additional information: <link linkId="editPageLink" accessKey="$helper.action.getTextStrict('navlink.edit.accesskey')">/pages/editpage.action?pageId=$helper.page.id</link>
Condition elementsCondition elements must contain a class attribute with the fully-qualified name of a Java class. The referenced class:
Condition elements can take optional parameters. These parameters will be passed in to the Condition's init() method as a Map of String key/value pairs after autowiring, but before any condition checks are performed. For example: <condition class="com.atlassian.confluence.plugin.descriptor.web.conditions.PagePermissionCondition"> <param name="permission">edit</param> </condition> Multiple condition elements can be included in a single web item. If a web item contains multiple conditions, all conditions must be satisfied for the web item to be displayed. To invert a condition, add the attribute 'invert="true"' to the condition element. This is useful where you want to show the section if a certain condition is not satisfied. Web Section DefinitionHere's a sample atlassian-plugin.xml for a web section: <web-section key="mail" name="Mail" location="system.space.admin" weight="300"> <label key="space-mail" /> <condition class="com.atlassian.confluence.plugin.descriptor.web.conditions.NotPersonalSpaceCondition"/> </web-section>
Q and AHow do I make use of sections or web items in my own themes?Take a look at how they are used in the default themes, you should be able to get a good idea of the necessary code. For example, here is some sample code from space.vmd #foreach ($item in $action.webInterfaceManager.getDisplayableItems("system.space", $action.remoteUser, $helper)) <li><a href="$item.link.getDisplayableUrl($req, $helper)" #if ($context == $item.key) class="current" #end> $item.label.getDisplayableLabel($req, $helper) </a></li> #end Can I create new locations for web UI plugins in my own themes?Yes. Just pick a new key for the location or section parameters of your plugin modules. By convention, you should probably use the standard 'inverted domain name' prefix so as not to clash with anyone else's plugins. We reserve all system.* locations for Confluence's core use. Once again, however, we don't recommend this as you end up with plugins that are only useful in your own themes. Try to at least provide an alternative set of UI modules for people who are using other themes and still want to access the same functionality. You could, for example, define alternative UI plugin modules that placed your functions in Confluence's standard locations, but have a <condition> that disabled them in favour of your custom locations if your theme was installed. If I create a Web Item that links to my custom action, how do I make it appear in the same tabs/context as the other items in that location?The best way is to look at the .vm file of one of the existing items in that location. You are most interested in the #applyDecorator directive being called from that file. For example viewpage.vm, which defines the "View" tab in the system.page location has the following #applyDecorator directive: #applyDecorator("root") #decoratorParam("helper" $action.helper) #decoratorParam("mode" "view") #decoratorParam("context" "page") <!-- some stuff... --> #end If you were writing a plugin that was destined to be added as another item in the page tabs, your Velocity file for that action would also have to have a similar decorator directive around it: #applyDecorator("root") #decoratorParam("helper" $action.helper) #decoratorParam("mode" "myPluginKey") #decoratorParam("context" "page") <!-- some stuff... --> #end Note that you should put you Web Item's plugin key as the "mode". This way, Confluence will make sure that the correct tab is highlighted as the active tab when people are viewing your action.
|
![]() |
Document generated by Confluence on Oct 10, 2007 18:36 |