Is there a way to get a list of pages within a space, and their associated labels?
Asked by ice-ccull:

We have about 100 "content" pages in a space (today). When we create "content" pages, we are supposed to attach 4 labels and keep them updated, and then I have "grouping" pages that use the "Page Properties report Macro" to display "content" pages matching a specific label.

The issue and risk I am finding is that it's possible that if labels aren't updated (or even worse, were never attached), "content" pages could get lost if they never show up in the "grouping" pages.

Is there a way to see any of these lists?:

* all pages in a space that do not have a label
* all pages in a space that does not have one of these labels (Label_a, Label_b)
* all pages in a space, with their labels listed beside them
* all pages in a space, with their labels and page properties

Thank you.

We're using Confluence 5.5.2.


Answers:
author: ice-ccull
body: 1. I was able to create a User Macro to display all pages in the space that do not have a label. Here is the code:

   ```
   ## @noparams#set($containerManagerClass=$action.class.forName('com.atlassian.spring.container.ContainerManager'))#set($getInstanceMethod=$containerManagerClass.getDeclaredMethod('getInstance',null))#set($containerManager=$getInstanceMethod.invoke(null,null))#set($containerContext=$containerManager.containerContext)   ## the pageManager gives you access to the pages#set($pageManager =$containerContext.getComponent('pageManager'))        &lt;b&gt;Unlabeled pages in space $space.name&lt;b&gt;    &lt;ul&gt;    #foreach( $page in $pageManager.getPages( $space, true) )           #if( $page.labels.size() == 0 )               &lt;li&gt;&lt;a href="$req.contextPath$page.urlPath"&gt;$page.title&lt;/a&gt;&lt;/li&gt;        #end    #end    &lt;/ul&gt;
   ```

2. I was able to create a User Macro to display all pages in the space and their associated labels.

   ```
   ## @noparams#set($containerManagerClass=$action.class.forName('com.atlassian.spring.container.ContainerManager'))#set($getInstanceMethod=$containerManagerClass.getDeclaredMethod('getInstance',null))#set($containerManager=$getInstanceMethod.invoke(null,null))#set($containerContext=$containerManager.containerContext)   ## the pageManager gives you access to the pages#set($pageManager =$containerContext.getComponent('pageManager'))        &lt;b&gt;Pages in space $space.name and their associated labels.&lt;b&gt;    &lt;ul&gt;    #foreach( $page in $pageManager.getPages( $space, true) )             &lt;li&gt;&lt;a href="$req.contextPath$page.urlPath"&gt;$page.title&lt;/a&gt; - $page.labels&lt;/li&gt;    #end    &lt;/ul&gt;
   ```

comments: author: RWilburn
body: I know it's been a few years since you posted this... Thank you! It is very helpful! I am using the one that lists the labels associated with each page, and it works great!

I would also like to be able to see a list of pages associated with each label. The Labels list macro does this, but I'd like to see the list of pages without having to click each label. It seems like it should be simple to modify your code above to do that, but I am struggling with it. Is there any way you could help with this?

Thank you!!


author: ice-ccull
body: Honestly,

I probably haven't looked at this since 2015. Hopefully someone else can help or there's additional guidance out there.

I am glad to hear that I was able to contribute somewhat positively though!

Good luck finding a way to get what you're looking for!

Chad


author: RWilburn
body: LOL! I thought it was a long-shot after so many years. Thank you for replying, though! And, yes, your macro is very helpful for sure!

Thank you!

Rhoda