User macro accessing content properties?

takilara August 2, 2021

Hello,

I use Content Property to store JSON data on pages through the REST API. I store this with key "quest". The value is a json, containing for instance "QuestName" and "QuestLevel".

I have this property set on approx 400 pages, these are all children of a common page.

 

I would like to access these content properties from a user macro.

I have been able to get the properties using the AJS and the REST api as follows:

jQuery.when(jQuery
.getJSON("/rest/api/content/$content.getIdAsString()/property/quest"))
.
done(function(json) {
console.log(json["value"]["QuestLevel"])
});

While this works well for a user macro that sits on the page with the Content Property, it is not ideal for a user macro that collects this property from all pages that has it. (Or at least, i am not proficient enough in JavaScript to generate the correct query that handles pagination

First Question: What is the ideal way to do this? Assume i would like to output a table that lists the various elements of the json as columns with one row per page that has the "quest" property.

 

I have a feeling that this is possible to do using the Velocity templating functions. This seems easier than doing it through javascript.

I have the following now:

#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( $pageManager=$containerContext.getComponent('pageManager') )

#set ( $questsPage=$pageManager.getPage(17530885) )
#set( $descendants=$questsPage.getChildren() )

<br>
Page ID: $content.getIdAsString()
<br>
Quest Page: $questsPage

<br>
<ul>
#foreach( $descendant in $descendants )
#set( $childProps=$descendant.getProperties().asList() )
<li>$descendant.getDisplayTitle()
<ul>
#foreach( $prop in $childProps )
<li>$prop.getStringProperty( "quest" )</li>
#end
</ul>
</li>
#end
</ul>

This will list all the children, and will show that there are properties, but i am unable to "get" the actual contents of the property... (i am fairly sure i am not using the getProperties() or getStringProperty() correctly)

Second Question: How to i access the value and elements of the "quest" Content property using the ContentEntityObject.getProperties() ?

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
7.11.2
TAGS
AUG Leaders

Atlassian Community Events