Confluence 2.9 : Creating a Theme Plugin
This page last changed on Jul 10, 2008 by david@randombits.org.
Using DecoratorsA decorator defines Confluence page layout. By modifying a decorator file, you can move "Attachments' tab from the left of the screen to the right or remove it completely. Decorator files are written in the Velocity templating language and have the VMD extension. You can familiarise yourself with Velocity at the Velocity Template Overview and decorators in general at the Sitemesh homepage. Decorators, Contexts and ModesConfluence comes bundled with a set of decorator files that you can customize. Instead of having one decorator file for each screen, we've grouped together similar screens (example: view and edit page screens) to simplfy editing layouts. There is some terminology that we use when talking about decorators that should be defined. We've grouped all the screens in Confluence into major categories which we call contexts. Within each context are various modes (ways of viewing that particular layout). The following table summarises how decorators use contexts and modes:
ExampleAs an example on how to use the table above, say we found the 'Attachments' tab on the view page screen annoying and wanted to remove it. We could make this layout change in the page.vmd file - where the 'view' mode is handled (as shown below). #* Display page based on mode: currently 'view', 'edit', 'preview-edit', 'info' and 'attachments. See the individual page templates (viewpage.vm, editpage.vm, etc.) for the setting of the mode parameter. *# ## VIEW #if ($mode == "view") <make layout modifications here> #elseif ...
The Theme Helper ObjectWhen editing decorator files you will come across a variable called $helper - this is the theme helper object. The following table summarises what this object can do:
If you are on a page or space screen you also have access to the actual page and space object by using $helper.page and $helper.space respectively. If you want to delve more into what other methods are available in this object, please see our API's for ThemeHelper. Velocity macrosFinally, the last thing you need to decipher decorator files is an understanding of macros. A velocity macro looks like this: #myVelocityMacro() In essence, each macro embodies a block of code. We've used these macros to simplify decorator files and make them easier to modify. For example, the #editPageLink() macro will render the edit page link you see on the 'View Page Screen'. All the logic which checks whether a certain user has permissions to edit pages and hence see the link are hidden in this macro. As the theme writer, you need only care about calling it. The easiest way to acquaint yourself with the macros is to browse through your macros.vm file, located in /template/includes/macros.vm (under the base Confluence installation). Writing your own Velocity MacrosVelocity macros are very useful for abstracting out common presentation logic into a function call and for keeping decorators clean. If you wish to use them for your theme you can either: Write your own Macros fileWrite your own Velocity macros library file, as we've done with macros.vm. If you elect to do this you must locate the velocity.properties file beneath WEB-INF/classes and tell the Velocity engine where your library file can be located, relative to the base installation of Confluence. velocimacro.library = template/includes/macros.vm Use Inline Velcoty Macros.Inline velocity macros, when loaded once, can be called from anywhere. See decorators/mail.vmd for examples of inline decorators. Using StylesheetsStylesheets can be defined for a theme and they will automatically be included by Confluence when pages are displayed with your theme. You simply need to add a resource of type download to your theme module. Please note that the resource name must end with .css for it to be automatically included by Confluence. <theme key="mytheme" .... > ... <resource type="download" name="my-theme.css" location="styles/my-theme.css"/> ... </theme> Now, in the HTML header of any page using your theme, a link tag to your theme stylesheets will be created by Confluence. If you have a look at the source of combined.css, it will contain imports to all your theme stylesheets. <html> <head> ... <link type="text/css" href="/confluence/s/.../_/styles/combined.css?spaceKey=FOO" rel="stylesheet"> </head> ... </html> Theme stylesheets are included after all the default Confluence styles and colour schemes. This is to ensure that your theme styles can override and take precedence over the base styles provided by Confluence. Using Colour SchemesUsers can customise their own colour scheme (regardless of the theme selected) for a particular space under Space Administration. ![]() You may choose to respect these user configured colour schemes in your theme or ignore them completely by overriding them in your theme stylesheets. If you would like to respect the configured colour schemes for your new UI elements, you should specify a velocity stylesheet resource in your theme module. <theme key="mytheme" .... > ... <resource type="download" name="my-theme-colors.vm" location="templates/clickr/my-theme-colors.vm"/> ... </theme> Please note that the resource name must end with .vm for it to be automatically rendered as a velocity template by Confluence. This velocity stylesheet will essentially contain css for colours with references to the colour scheme bean (which is available to you via the action). For example: \#breadcrumbs a { color: $action.colorScheme.linkColor; } #myNewElement { color: $action.colorScheme.headingTextColor; } .myNewElementClass { border-color: $action.colorScheme.borderColor; } ...
Additionally, you may choose to provide your theme with a pre-defined colour scheme (which users will be able to select under Space Administration). This pre-defined colour scheme will take precedence if no custom user one is defined for the space. To define a theme's colour scheme, you need to add a colour scheme module and link to it in the theme module. For example: <theme key="mytheme" .... > ... <colour-scheme key="com.atlassian.confluence.themes.mytheme:earth-colours"/> ... </theme> ... <colour-scheme key="earth-colours" name="Brown and Red Earth Colours" class="com.atlassian.confluence.themes.BaseColourScheme"> <colour key="property.style.topbarcolour" value="#440000"/> <colour key="property.style.spacenamecolour" value="#999999"/> <colour key="property.style.headingtextcolour" value="#663300"/> <colour key="property.style.linkcolour" value="#663300"/> <colour key="property.style.bordercolour" value="#440000"/> <colour key="property.style.navbgcolour" value="#663300"/> <colour key="property.style.navtextcolour" value="#ffffff"/> <colour key="property.style.navselectedbgcolour" value="#440000"/> <colour key="property.style.navselectedtextcolour" value="#ffffff"/> </colour-scheme> The class of a colour scheme must implement com.atlassian.confluence.themes.ColourScheme. The com.atlassian.confluence.themes.BaseColourScheme class provided with Confluence sets the colours based on the module's configuration. The available colours correspond to those that you would configure under Space Administration > Colour Scheme:
![]() ![]() ![]() |
![]() |
Document generated by Confluence on Aug 07, 2008 19:08 |