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

How to access values inside a "page properties macro"(!) on the same page from a user macro?

Olaf Kueppers September 2, 2015

Hi all,

i set up several pages with "page properties macros" (which shall be hidden in the final approach) but want to display values from there in the current page via user macro.

Is that possible? I know the documentation says that "It is not possible to reference the metadata using the metadata key from within the page, or anywhere else on a Confluence page." but can we maybe succeed in an approach using REST or some other query against the confluence database?

If the page can render the information (given the macro is not "hidden") why can't we do this in another macro on the same page (admittedly effectively rebuilding the display part of the marco, but this time with the chance to format labels and values and to rearrange them)

Hope someone knows about that

Best regards
Olaf

PS: All the articles i have read so far aimed at displaying "normal" properties related to the page, not at displaying properties located inside the "page properties macro"

5 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

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.
December 8, 2015

Well, I have a thought. You could wrap your page properties macro within your user macro like this ...

image2015-12-8 9:28:30.png

In the user macro definition do something like this ...

## Developed by: Davin Studer
## Date created: 12/08/2015
## @noparams
 
#set($id = $action.dateFormatter.calendar.timeInMillis)
<div id="ppContainer$id">$body</div>

The $id is so that you have a unique id in case you add it more than once to a page. Then you could use JavaScript in your user macro to get at the data like this ...

<script type="text/javascript">
AJS.toInit(function(){
	// This would loop through all the key/value pair table rows.
	AJS.$('#ppContainer${id} .plugin-tabmeta-details table tr').each(function(index){
    	var key = AJS.$('th', this).text();
	    var value =  AJS.$('td', this).text();
	});
	
	// This would target a specific key/value pair row.
	var row = AJS.$('#ppContainer${id} .plugin-tabmeta-details table th:contains("Key 2")').parent();
	var key = AJS.$('th', row).text();
	var value =  AJS.$('td', row).text();
});
</script>

Here is the full thing.

## Developed by: Davin Studer
## Date created: 12/08/2015
## @noparams
 
#set($id = $action.dateFormatter.calendar.timeInMillis)
<div id="ppContainer$id">$body</div>
 
<script type="text/javascript">
AJS.toInit(function(){
	// This would loop through all the key/value pair table rows.
	AJS.$('#ppContainer${id} .plugin-tabmeta-details table tr').each(function(index){
    	var key = AJS.$('th', this).text();
	    var value =  AJS.$('td', this).text();
	});
	
	// This would target a specific key/value pair row.
	var row = AJS.$('#ppContainer${id} .plugin-tabmeta-details table th:contains("Key 2")').parent();
	var key = AJS.$('th', row).text();
	var value =  AJS.$('td', row).text();
});
</script>
Malcolm Cook January 14, 2016

Lo! this works a treat. Thanks! But.... will it survive a re-implementation of how page properties are represented?

0 votes
Olaf Kueppers December 9, 2015

Hi all

thanks Gavin for providing such a nifty little thing to encapsulate that macro and provide accessors to the values with it...

Though we do not need that specific thing anymore since we switched to realizing our requirements with the metadata macros, I still consider that technique very inspiring!

Hoppe everyone watching my issue will find something useful!

Best regards

Olaf

0 votes
Eric Toussaint December 8, 2015

If you have Comala workflow installed you can use the "Get-Metadata" macro to display page properties or workflow metadata as well

0 votes
thomasfogh December 8, 2015

I am wanting to do this as well! It would be great to be able to fetch values from the data "inside" the Page Properties macro and display the e.g. through a user macro. Unfortunately I'm not a hardcore developer. Hope someone can figure this out soon.

0 votes
Pascal Havelange October 14, 2015

I'm looking for the exact same thing.

No-one has a clue how to achieve this?

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