Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to access a page property via macro

Adolfo Casari
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.
January 28, 2015

I need to access a page property via a (user) macro.

Is this possible?

1 answer

1 accepted

1 vote
Answer accepted
Davin Studer
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.
January 28, 2015

Is this what you are looking for?

#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'))
 
$contentPropertyManager.setStringProperty($content, "myProperty", "Stuff")
$contentPropertyManager.getStringProperty($content, "myProperty")
Adolfo Casari
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.
January 28, 2015

Thanks. myProperty would be set according to https://confluence.atlassian.com/display/DOC/Page+Properties+Macro (like Deadline in the example in that page), right?

Davin Studer
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.
January 28, 2015

Ah ... got it. You are looking for how to access values within a page properties macro. Not sure you could do it with a user macro. Mainly it is for paring with the page properties report macro.

Adolfo Casari
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.
January 28, 2015

$content is a reference to the current page objet? Your code showed me how to move forward. In my scenario myProperty is a JIRA issueId associated with a page that display info about that issue.

Cyrille Martin
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

Adolfo did you succeed in retreiving page properties in a User macro ?

Adolfo Casari
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 18, 2015

Yes.

Like Pat Ryan likes this
Olaf Kueppers August 31, 2015

@Adolfo: I also want to display values located in the page properties macro of the current page. Would you mind posting a code snippet of your successful approach here? i take it that Davin pointed you in the right direction but you had to develop the final thing? I would be very interested in what you ended up with. Thanks in Advance

Adolfo Casari
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.
September 2, 2015

You just need the last two lines of the snippet above. The first one to set a property and the second to read it.

Olaf Kueppers September 2, 2015

Thanks for the information. i tried it but didnt get any results regarding access to values inside the page properties macro on the same page (i assume that is what you originally asked about?) I guess i need to ask that specific question on my own, huh? :-) Thanks anyway!

Adolfo Casari
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.
September 3, 2015

That snippet is not for set/get Page Properties macro values, it's for your own values than can be set with a user macro and read within another. I used it to set a JIRA issueid to a confluence page and then use that issueid to query jira with a jiraissue macro.

Michael Howard
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 6, 2017

Thanks David, this worked for me.

Chris Amos December 12, 2017

Sorry for the newbie question, how would I integrate this, I seem to have the option of a user macro, a macro plugin or a full blown macro.

I have documents with a page property block with things like version and document number.

I want to have the document number and version in a footer.

It would seem a generic macro that just takes one parameter, the name of the property would do.

  $contentPropertyManager.getStringProperty($content, parameter1)

I need to can the solution and pass it to general purpose IT department to install.

TA

Chris

BTW: Am I missing the point, this is such an obvious thing to want to do, is it built in and I missed it?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events