Forums

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

How to list pages filtered by page content

John Fergus May 21, 2019

Hi,

 

I have a user-macro (called target-audience) on pages allowing the user to choose some boolean parameters indicating the target audience groups for the page. This macro renders bullet points for each chosen group. For example, below is a page where the chosen groups are GroupA and GroupB

 

image.png

 

I would like to create a page like below where I list the child pages of the current page that have the indicated groups as part of the target audience. For each list I would like to use a macro to chose the pages to display in the list. For example, in column one I would like a macro where I can specify pages containing GroupA as the target audience. 

image.png

Obviously a Children Display macro is close, but I cannot only choose to display certain of the child pages. Similarly, the Content by Label macro is close but I do not have labels on my child pages. 

 I could manually add labels to the child pages, but if i could automatically add them based on the target-audience macro that would be great. From reading questions here I can see that should be possible by using the REST API. 

 I looked at writing a new user-macro similar to Content by Label. My macro would examine children pages and look at the content to see if the content include the required groups. However in the macro I cannot see how to get the page content as it would be rendered. It gives me the content before the target-audience macro has run. Is there a way to see the content after the macro has run or a way to see into the macro and examine the boolean parameters to see which ones are set?

 Or is there some other approach I should take? Any thoughts appreciated.

 

Thanks, 

 John. 

1 answer

1 accepted

0 votes
Answer accepted
John Fergus June 27, 2019

To make this work I adapted my target-audience macro. As mentioned above, the macro sets boolean parameters depending on the values selected by the user. 

To make this work, I have a naming scheme where my custom labels will all be prefixed with 'ta-'.  In the macro code I create a JS array of label names that need to be added to the page.  I can now loop over all existing labels on the page that match 'ta-' and see if they are required. Those that are not required I can remove. I can then loop over the required labels and add those. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events