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.
1.
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.)
2.
Is it possible to define the data type of an object? Such as Key or User or ProfilePictureInfo etc.?
3.
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!
Manuel
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
#if($body)
#set($display = $body.trim())
#end
<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!
Manuel
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
Thanks!
Manuel
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You are welcome. I'm glad it's helpful.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.