Stand with Ukraine 🇺🇦

Collapsible Table of Contents for Child Pages

Table of Contents for Children - Show H1 headings for child topics to enable easy navigation - Preview 2
Table of Contents for Children - Show H1 headings for child topics to enable easy navigation - Preview 3
navigationconfluence-content

This macro dynamically generates a table of contents for the direct child pages of the current Confluence page. It uses the Confluence REST API to retrieve child pages and their content in JSON format. It identifies H1 headings in the child pages and renders them as anchor links within an unordered list. The table of contents updates automatically as the child pages or headings change.

Try for free

Template

## Get children of the current page
#set ( $children = $ConfluenceManager.get("/wiki/api/v2/pages/${page.id}/children").results )

<ul>
  
#if($children.isEmpty())
    No children pages were found for current page    
#else

## Note that not all Atlaskit design tokens (example: var(--ds-text, #ffffff)) work in static macros. Check that case by case
#foreach ( $child in $children )
  ## Get child content in JSON format
  #set ( $body = $ConfluenceManager.get("/wiki/api/v2/pages/${child.id}?body-format=atlas_doc_format").body.atlas_doc_format.value )

  <li><b>$child.title</b><br>

    #set ( $devider = "" ) ## skip first devider
    #foreach ( $item in $body.content )
      ## Triggers only on H1 headings
      #if ( $item.type == "heading" && $item.attrs.level == 1)
        #set ( $h1 = $item.content[0].text )
        $devider
        ## Render anchor link
        <ac:link ac:anchor="$h1">
          <ri:page ri:content-title="$child.title"/>
          <ac:plain-text-link-body><![CDATA[$h1]]></ac:plain-text-link-body>
        </ac:link>
        #set ( $devider = "|" )
      #end
    #end

  </li>

#end
#end
</ul>

Chosen by Top Global Companies Across Diverse Industries

BNP Paribas
Census
CNES
EDP
HHMI
HP
Hyundai
Index
Intercars
Melia
BNP Paribas
Census
CNES
EDP
HHMI
HP
Hyundai
Index
Intercars
Melia
Ministry
NVIDIA
PayPay
Pfizer
Qualcomm
Rail Canada
Red Cross
SEC
Space Institute
Telefonica
Ministry
NVIDIA
PayPay
Pfizer
Qualcomm
Rail Canada
Red Cross
SEC
Space Institute
Telefonica

Got Questions?

Fill out the form, and we'll guide you through every step of the way