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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

List only child pages with a specific label

Hi

I would like to list only child pages with a specific label in my Confluence page.

I can't see that this is possible with children-display.

Does anyone have a solution?

Regards,

Michael Danielsson

4 answers

1 accepted

1 vote
Answer accepted

Here's a user macro that does it (I varied from my suggested approach slightly):

## Macro title: Label Search
## Macro has a body: N
## Body processing: n/a
## Output: HTML
##
## Developed by: Matthew J. Horn
## Date created: 10/24/2013
## Installed by: Matthew J. Horn
## @noparams

## Define variables:
#set ($labelList = [])
## #set ($pageMatches = [])
#set ($counter = 0)
#set ($labelToMatch = "comments")

<strong>Search for "$labelToMatch" Label</strong><br/>

#macro( process $rp ) 
  #set( $pagelist = $rp.getSortedChildren() )
  #foreach( $child in $pagelist )   ## child is of type Page
      #set( $labelList = $child.getLabels() )    
      #foreach ($label in $labelList)
        #if ($label == $labelToMatch)
         <br/>$child.getTitle() has the "$labelToMatch" label on it
        #end
      #end
      #set( $counter = $counter + 1 )          
      ## make this 
      #if( $child.hasChildren() )
        #process( $child )
     #end
  #end
#end
## Check to see if the page is the home page of the space.
## Otherwise, get to the home page.
#if ($content.isRootLevel() == "false")
#set($spaceHome = $space.getHomePage())
   #process($spaceHome)
#else 
   #process($content)
#end    

<br/><br/><strong>$counter pages checked.</strong>

How do I get this macro to start with the current page and just check its children?

You should be able to do this with a user macro. On the parent page, get a List of child pages with the getDescendants() method. Then iterate over them and for each page call getLabels(). Check for the label you want, and build a list of the pages that match.

You can basically do all this with the Page class:

https://docs.atlassian.com/atlassian-confluence/latest/com/atlassian/confluence/pages/Page.html

hth,

matt

Hi,

I want to do it without any java coding.

Is that possible?

Regards,

Michael Danielsson

Writing user macros is not at all like Java coding. It uses Java syntax, but you don't do any compilation. Confluence takes care of that for you.

You could use the reporting plugin and do something like this:

{report-table}

{local-reporter:page:children|source=Page Name}

{content-filter:label=label name}

{local-reporter}

{report-column:title=Column Title}

{report-info:page:title}

{report-column}

{report-table}

Regards,

Kay

The page properties report can do this, but it will report the child pages' properties rather than a standard page listing. However, it does allow you to filter by label, and in "Add filter" you can limit it to direct children or to descendants of the current page.

That may work for some people who stumble across this question.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Confluence

What do you think is the most *delightful* Confluence feature? Comment for a prize!

- Create your own custom emoji 🔥 - "Shake for Feedback" on mobile 📱 - An endless supply of GIFs via GIPHY 🤩 Is there anything quite as nice as a pleasant surprise? Comment below with what...

408 views 23 8
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you