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

When creating a Confluence Macro, how does one utilize the API to retrieve the page on which the macro is added?

Brendan Lehman February 11, 2015

When creating a Confluence Macro, how does one utilize the API to retrieve the page on which the macro is added? I recognize the fact that one way to obtain a page is to use a PageManager to look it up by it's id (which is of data type long). I have been searching the documentation for a way by which to obtain this id, but to no avail. I noticed that the ID of the page is exposed in the URL of the "Edit" version of a page, but am unsure how to go about retrieving this. Any help would be greatly appreciated.

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Alex Medved _ConfiForms_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 11, 2015

Hi,

You are developing a macro, right?

And you class implements the https://developer.atlassian.com/static/javadoc/confluence/4.0/reference/com/atlassian/confluence/macro/Macro.html interface, right?

As entry point to your macro is:

execute(Map<StringString> parameters, String body, ConversionContext context)

then you can get the page through the "conversionContext.getEntity()"

The result is of type ContentEntityObject, which you can use to get the ID (getId() method, it will be an ID of the page or a blogpost, depends where you macro is used/placed )


Hope this helps!

 

1 vote
Yagnesh Bhat
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 11, 2015

Button text, Template name are macro parameters, they are configured in the descriptor atlassian-plugin.xml. https://developer.atlassian.com/confdev/tutorials/macro-tutorials-for-confluence/customising-the-display-of-macro-parameters-in-the-editor-placeholder gives more details about it.  All the details pertaining to developing macros are explained in the tutorials here :https://developer.atlassian.com/confdev/tutorials/macro-tutorials-for-confluence

0 votes
Brendan Lehman February 11, 2015

Thank you @Yagnesh Bhat, this is invaluable information. However, I would prefer to have similar functionality at the time of clicking a button on a page. The intention of this macro is to give the user the capability of specifying a positive integer as the number of pages to create/associate as children of the current page. Think of it as a 'Create Multiple Pages From Multiple Templates" Macro. These pages will be created from global page templates which were previously defined. I plan on having a number of labels and drop-down lists dynamically added to a modal dialogue box such that the number of labels and drop-down lists is equal to the aforementioned, user specified number. Once the user has chosen which global page templates to create the child pages from (and accepts by clicking a separate OK button) I would then like to create the pages and add them as children to the current page. Might you have any suggestions as to how I could approach this?

Yagnesh Bhat
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 23, 2015

I am not sure if you can create multiple pages out of a macro in one go like that. If you have some templates set up, the way I can think of creating pages out of that template is by creating a blueprint per template. Please check out these tutorials related to blueprints for further information : https://developer.atlassian.com/confdev/confluence-plugin-guide/confluence-blueprints/write-a-simple-confluence-blueprint-plugin

0 votes
Brendan Lehman February 11, 2015

Thank you very much! smile That's exactly what I needed. As a follow up question, is there any way that I might be able to access common features of existing Confluence macros? Specifically, I'd like to be able to create a modal dialogue box similar to the one made available when choosing which global page template to utilize when using the 'Create Page From Template' Macro? (See Image Below) If not, then I can use JS and HTML to build my own, although this seems very tedious to do w/i the execute method using a StringBuilder. If there is a better alternative, then i am all ears.

image2015-2-11 14:56:24.png

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events