We create the tab effect in two key stages:
The actual implementation of this is quite verbose - so verbose that we're already thinking of ways to make it cleaner (we'll update this tutorial when we do).
We start with a block of wiki notation like the following, on thepage (which also contains the tab images as page attachments):
In itself, this is fairly simple syntax - it's just a load of images with links wrapped round them. The active tag is marked by a
class=stab ("selected tab") in the menulink that wraps the tab image - we'll explain why later in 4 - CSS.
The notation shown above will only be shown when you're looking at the page with title "Home" - otherwise it'll be hidden. There is a similar block of wiki notation for each of the other tabs that will show all tabs with the relevant tab selected depending on what you are looking at.
One of the limitations of Confluence is that you can't nest macros and this posed a problem because we wanted to use the builder-show macro within another builder-show macro.
To get round this problem we created a user macro called "bshow", set it to have a body (unprocessed) and output wiki notation. The macro template is as follows:
When you then call:
The actual output is rendered as:
This effectively allows us to nest one builder-show macro within another and solves our problem.
For the selected tab, we also use an inline style to set the background colour of the left slider bar to the same colour as the selected tab:
This is a bit hacky but it has the major benefit of giving us complete control over the tab colours on a space by space basis and also ensuring the correct slider bar colour is set only when the associated tab is selected.
We mentioned at the start of the tutorial that the full wiki notation was somewhat verbose - here it is in full:
It's a bit nasty - lots of duplication, but luckily fairly low processing overhead as only one chunk at most will be rendered by the server depending on your location within the space.
You'll also notice that if you are in an area not covered by the tabs, no tabs will appear - we could have added another block of notation which had no selected tab, however we decided not to because we were in a rush!