Access Keys:
Skip to content (Access Key - 0)

<< Plugins Blog

Show the right things to the right people! Confluence plugins to set the visibility of elements in your themes and pages

Aug 19, 2011 13:48

Confluence Wikis are often used by a variety of people for a variety of purposes. Consequently, you don't want to always show the same content to all users. Confluence has some really great fine-grained page permissions that allow you to limit who can see certain pages to individuals or groups of users, but sometimes even these just aren't specific enough - what if you want to show/hide certain page/theme elements to just some users? Perhaps you want to display a message to a space administrator but not to other end-users? Or what if you want to take this even further, showing different content depending on whether the content is being viewed or edited, whether it's a blog or a page, and whether or not it was created before or after a particular date?

Well you can achieve all of these things with the macros provided in Customware's Visibility plugin and our own Theme Builder plugin. Theme Builder is part of our Essentials Plugin Pack - a collection of 19 free Confluence plugins.

 

The Visibility plugin macros allow you to show or hide content based on a user's name, groups or space access, by defining parameters within its hide-from, show-to, hide-if and show-if macros. There are options to set content visibility dependent upon the type of content, the labels the content has and the display mode it is being viewed in amongst others.

Theme Builder provides similar macros, builder-show and builder-hide, that are specifically for use within Builder theme panels - you can set content visibility in many of the same ways as the Visibility plugin, but also specify whether the page has a particular title, whether specified content exists, and whether it was created before or after a specified date or time period and more.

There is some overlap between these plugins in terms of the macro functionality offered - however, it's this overlap that gives you the most power - you can overcome Confluence's limitation of not being able to nest macros, by combining the macros from the different plugins. This means that you can be very specific in determining which page elements get displayed, covering nearly all use-cases.

Lets take a look at a couple of examples:


{builder-hide:hastitle=Home, About, Menu}
{builder-show:mode=view}
{table:width=100%}{tr}{td:width=50%|align=left}
*[<< Back to home|Home]*
{td}
{td:width=50%|align=right|id=admincontrols}
{show-to:group=web-staff}
{align:right}Remember to check the page labels{align}
{show-to}
{td}
{tr}
{table}
{builder-show}
{builder-hide}

 

In this example, we start by using {builder-hide} to hide all content if the theme is being used on pages titled 'Home', 'About' or 'Menu' - these could be all of the pages at the root of the page hierarchy - it's only when we've dug down in to the pages within the space that we want to display the content. Then we use {builder-show} to only display the content if the page is being viewed - so when a user edits the page, they won't see the content, which in this case is a link back to the page 'Home'. Finally, we use the {show-to} macro to limit who some text is displayed to - here we just show staff in the Web Team a message to remember to check the page labels. End users don't need to know this, so it isn't showed to them.


In our second example we start by hiding all content if it is a blogpost that is being edited, otherwise it is displayed. However, it's only displayed to confluence-users. Since some users might be in both the confluence-users and confluence-administrators group, we then add a condition to hide some content from confluence-administrators. The content is a message that is only shown if the page was modified more than one year ago. However, regardless of whether they are in the confluence-administrators group or not, we show a message to all confluence-users on pages that were modified more than one year, six months, one day and one hour ago.

 

{builder-hide:mode=edit|context=blogpost}
{show-to:group=confluence-users}
{hide-from:group=confluence-administrators}
{builder-show:olderthan=1y}
Check with the creator whether this is still up to date.
{builder-show}
{hide-from}
{builder-show:olderthan=1y6m1d1h}
Warning - this content might be out of date.
{builder-show}
{show-to}
{builder-hide}

Hopefully, these examples will give you some ideas on how you can combine these visibility macros to create themes and pages that really work for you and your different audiences. Last week, I covered how you can combine the Replace and Render plugin with other plugins to create something more powerful too, so you might want to check that out.

If you have any questions or comments, then let us know on our Community site.

Adaptavist Theme Builder Powered by Atlassian Confluence