Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to include a class in a user macro?

Hey there!

I am pretty a beginner in coding Confluence User Macros but have some experience in object oriented languages, such as VB and VBA. I never coded HTML, Java or CSS.


Can I include other classes into my code, so I can use more functions, methods and properties. However I cannot find a tutorial to do this in a Confluence User Macro. For example I would like to show the mail address, personal information or phone number of a user.

I found this page that says I can use $config, $rederContext, $space and $content to access to these four classes, and I can use a bunch of other classes as described here . But nothing could yet help me out to display the user information.

(Maybe you can give me a link to a tutorial how to properly use this page. That would be really nice. It's frustrating to find functions I can use in the editor.)


Is it possible to define the data type of an object? Such as Key or User or ProfilePictureInfo etc.?


Can you recommend an IDE to write User Macros or Plugins in Confluence or Jira? I just installed Visual Studio and Eclipse but the Atlassian IDE Connector does'nt seem to be compatible with the actual versions. (I really miss the auto complete function.. :-) )


Thank you in advance!



2 answers

1 accepted

0 votes
Answer accepted
Bill Bailey Community Leader Aug 27, 2019

You have stumbled upon one of the vary powerful, but under-documented features of Confluence. To first give you a simple answer, yes you can included a class. For example, here is a simple macro  that sets a class around the text inside the macro:

## Check if the body exists
#set($display = $body.trim())

<p class="figtitle">$display</p>

Then take a look at my answer to a similar question User-Macro-Language-Reference.

It should get you started down the rich and rewarding path of a user macro writer. ;-)

Hey @Bill Bailey , thank you for your links. i really liked your article regarding the Wrapper Macro. That gave me some inspiration, since the motivation you describe is often like mine, too.

The links to the Velocity Engine showed me that I was already looking at the right places. Mabe I should read that site again more carefully. Thank you, though!

Your code example above ("<p class ...") - as I understand it - defines a new class, right? That will be surely useful later. But my main question is:
--> Can I refer to a chosen class from the Atlassian Confluence API?

Thank you!


Bill Bailey Community Leader Aug 28, 2019

Sorry, you said class and I thought CSS. ;-) Yes you have access to Confluence JAVA objects and methods but there are limitations. Here is a list of objects available in the Confluence Velocity context:


You can also add objects to the velocity context with some cleverness (this is not from me - I am not smart enough), for example:

## ContentPropertyManager setup
#set ($containerManagerClass=$content.class.forName('com.atlassian.spring.container.ContainerManager'))
#set ($getInstanceMethod=$containerManagerClass.getDeclaredMethod('getInstance',null))
#set ($containerManager=$getInstanceMethod.invoke(null,null))
#set ($containerContext=$containerManager.containerContext)
#set ($contentPropertyManager=$containerContext.getComponent('contentPropertyManager'))

So that I can do something like this to retrieve data stored by another macro:

## Retrieve doc title from scroll pagetitle macro and clean file name
#set($fileName=$contentPropertyManager.getTextProperty($content, "metadata.scroll.pagetitle"))

You can also add objects via a plugin, using the velocity-context-module. BTW, you can also package user macros using the user-macro-module.

Hey @Bill Bailey  thank you for your detailed answer. This is exactly what I need to know.

Now just for a last outlook before I'll get "into the doing":

 1.  Are Plugins or Apps more open regarding those "limitations" compared to user macros?

2. What IDE do you recommend and how to tell it the language reference of confluence?



Bill Bailey Community Leader Aug 28, 2019

Yes, plugins give you complete access to the API, but there is more overhead in development.

I tried to use an IDE before but wasn't that useful to me. I currently just use Notepad++ with Velocity language pack. I haven't tried it yet, but @Davin Studer editor plug in looks promising.

I have used the SDK before for complex macro development as it spins up a dev version of Confluence -- its console gives valuable feedback.

OK @Bill Bailey thank you so far. I think I'll keep that in mind for when I have to break through the given limitations.

0 votes
Davin Studer Community Leader Aug 27, 2019

Also, if you are going to be writing user macros I've written a free app in the marketplace for enhancing the user macro editing experience. There are a bunch of features lacking in the user macro exiting experience and I've tried to cover a bunch of the pain points.

Enhanced User Macro Editor

Hey @Davin Studer, thanks for your reply. And think what: I already had your plugin installed before I made this post. Great piece of work. Thanks for that!

Davin Studer Community Leader Aug 28, 2019

You are welcome. I'm glad it's helpful.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Confluence

What do you think is the most *delightful* Confluence feature? Comment for a prize!

- Create your own custom emoji 🔥 - "Shake for Feedback" on mobile 📱 - An endless supply of GIFs via GIPHY 🤩 Is there anything quite as nice as a pleasant surprise? Comment below with what...

402 views 23 8
Join discussion

Community Events

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

Events near you