I want to start a discussion on if & how user macros are used in Confluence Server instances around the world. At our company we use them quite a lot to get more out of existing Confluence macros, where the devs just stopped thinking...
A quick example
Everybody knows the Livesearch macro: It can be used to quick search your Confluence site with support for space & label filtering. You can even restrict the search to certain content types: Pages, blog posts, comments, space desc... And there they stopped thinking. Global search supports a filter on attachments. This macro does not. Seems that someone just didn't want us to have a decent attachment filter.
But that doesn't mean that the macro doesn't support attachment filtering. Creating a user macro which inserts the "attachment" content type instead of the ones offered in the selection does the job:
## Macro title: livesearchattachment
## Macro has a body: N
## @param Space:title=Space Key|type=string|desc=Empty:Current Space, @all:All spaces
## @param Placeholder:title=Placeholder|type=string|desc=Placeholder Text|default=Search Attachments...
## @param Instruction:title=Help Description|type=string|desc=Some help description displayed just below the search form|default=Minimum 3 chars, placeholder (*) is allowed and supported:
## Some param handling on the space parameter
## Use current space key & keep it if Space parameter is empty
## If @all is used, all spaces are searched by clearing the usespace variable
#if($paramSpace && $paramSpace != '')
#set($usespace = $paramSpace)
#if($usespace == '@all')
#set($usespace = '')
## Create a livesearch macro (Use the Confluence Source Editor AddOn available for Server)
<ac:structured-macro ac:macro-id="c3ad7372-421a-4a73-a8fd-a63b5c3d95be" ac:name="livesearch" ac:schema-version="1">
#if($usespace != '')
## Non empty space, filter on given space & do not display space name in results
## If no spaceKey parameter is generated, all spaces are searched
## This one does the trick: Just set attachment as type...
#if($paramInstruction && $paramInstruction != '')
<p<span style="font-size: 10px;">$paramInstruction</span></p>
What do you need to start experimenting?
What can go wrong?
Well, writing User Macros can only be done by System Admins. Atlassian might know why... These macros generate code inside a Confluence page. If you got a typo, forget to render valid HTML, etc... your page might be broken, ie. it doesn't display anymore, shows errors, etc.
What should work in these cases:
The page should now be opened in Edit mode allowing to fix the possible macro. Another option is certainly fixing the macro itself...
Where does this head to?
Please comment on how you use User Macros. Should we create a sort of repository in the community? Is there a Bitbucket repo already collecting macros?
Feedback MOST welcome!
It’s been great to hear from fellow users over the last few weeks about the best tips and fun moments you’ve had working on Confluence since the transition to working remote. I’d love to keep the c...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events