This page last changed on Dec 16, 2010 by smaddox.

This page tells you how to create a user macro that displays a coloured status lozenge. It is useful for showing the status of a project, for example. (For full details about creating a user macro, see the guide to writing user macros.)

A Working User Macro

This is a working user macro that you may want to install onto your Confluence site. In a future release, we intend to bundle this user macro with Confluence. At present, we are making it available on this documentation page so that you can try it out.

Defining the 'Status' User Macro

To create the 'Status' user macro,

  1. Go to the Confluence Administration Console and click 'User Macros' in the left-hand panel.
  2. Click the link on the text 'Click here to create a new User Macro' at the top of the list of macros.
  3. Enter the macro attributes as follows:
    • Macro Name: status
    • Visibility: Visible to all users in the Macro Browser
    • Macro Title: Status
    • Description: Displays a coloured status lozenge
    • Categories – Select all of the following:
      • Confluence Content
      • Reporting
      • Visuals & Images
    • Icon URL: /images/icons/macrobrowser/status.png
    • Documentation URL: http://confluence.atlassian.com/x/UxpODQ
    • Macro Body Processing: No macro body
    • Output Format: HTML
    • Template:
      ## @param colour:title=Colour|type=enum|enumValues=Grey,Red,Yellow,Green|required=true
      ## @param title:title=Status Title|type=string|desc=Title for the status lozenge. If left blank, the colour of the lozenge will appear as the title.
      ##
      ## Set up maps from colour names to RGB values
      ##
      #set ($backColours = { "RED" : "#ffe7e7", "YELLOW" : "#ffd",
       "GREEN" : "#ddfade", "GREY" : "#f0f0f0" })
      #set ($borderColours = { "RED" : "#df9898", "YELLOW" : "#f7df92",
       "GREEN" : "#93c49f", "GREY" : "#bbb" })
      ##
      ## If the colour name is unknown, fall back to grey
      ##
      #set ($paramcolour = $generalUtil.htmlEncode($paramcolour.toUpperCase()))
      #if (!$backColours.containsKey($paramcolour))
         #set ($paramcolour = 'GREY')
      #end
      ##
      ## Get the RGB colours for the background and border
      ##
      #set ($backColour = $backColours.get($paramcolour))
      #set ($borderColour = $borderColours.get($paramcolour))
      ##
      ## Use the colour as the title if none entered
      ##
      #if ($paramtitle)
         #set ($lozengeTitle = $generalUtil.htmlEncode($paramtitle))
         #if ($lozengeTitle.trim() == "")
             ##
             ## Allow the user to create a blank lozenge by entering a space for the title
             ##
             #set ($lozengeTitle = " ")
         #end
      #else
         #set ($lozengeTitle = $paramcolour)
      #end
      ##
      ## Create the status lozenge as an HTML span element
      ##
      <span style="background: $backColour; border: 2px solid $borderColour;
       color: black; font-weight: bold; padding: 4px 12px; -moz-border-radius:3px;
       -webkit-border-radius: 3px; display: inline-block; text-align:center;
       min-width:60px;">$lozengeTitle</span>
      
  4. Click 'Save'.

Example and Usage of the 'Status' Macro on a Page

See the user guide for the Status macro.

RELATED TOPICS

Writing User Macros

Document generated by Confluence on Mar 16, 2011 18:31