Mundorévès

Cada día me veo en un mundo al revés

News from Jul 21, 2008

  2008/07/21
Customizable Style Sheets in Confluence Themes
Last changed: Jul 21, 2008 14:32 by Roberto Dominguez
Labels: confluence

I've been using a trick for allowing customizing CSS in the Approvals Workflow Plugin and in themes.

The trick proved to be very handy in a recent high-speed project with Headshift I just completed. The Designer was able to make last-minute CSS tweaks by simply updating an attachment. I would later update the theme's stylesheet.

The way it works is by using an attachment in the space's home page as an alternative stylesheet.

A helper checks if the attachment styles.css exists in the space's home page, and if so, it will return a link to if as a stylesheet, which is included in the HTML.

public class CssHelper {

    private static final String CUSTOM_CSS_NAME = "styles.css";

    private SpaceManager spaceManager;

    public String getImportThemeCssLink(String spaceKey, String contextPath) {
        Space space = spaceManager.getSpace(spaceKey);
        if (space == null) {
            return "";
        }
        Page homePage = space.getHomePage();
        Attachment attachment = homePage.getAttachmentNamed(CUSTOM_CSS_NAME);
        if (attachment == null) {
            return "";
        }
        return "<link rel=\"stylesheet\" href=\"" +
                contextPath + "/download/attachments/" + 
                homePage.getIdAsString() + "/" + CUSTOM_CSS_NAME +
                "\" type=\"text/css\" />";
    }

    public void setSpaceManager(SpaceManager spaceManager) {
        this.spaceManager = spaceManager;
    }
}

it has to be defined in atlassian-plugin.xml:

    <velocity-context-item key="cssHelper" name="Theme CSS Helper" 
          context-key="cssHelper"
          class="com.headshift.confluence.css.helper.CssHelper"/>

In the main.vmd you can add the following at the end of the <head> section:

$cssHelper.getImportThemeCssLink($spaceKey,$req.contextPath)

That's it! the extra CSS will be included only if it exists.

Posted at 21 Jul @ 2:05 PM by Roberto Dominguez | 3 Comments

July 2008
Sun Mon Tue Wed Thu Fri Sat
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

Aug 04, 2008
Jul 20, 2008