Is there a macro which highlights on which pages a user macro is in use in Confluence?

Hi All,

I would like to get a list which display on which pages a user macro is in use in Confluence. Is there a such macro or feature?

Thanks for your help!

Rumi

3 answers

1 accepted

There are two plugins you could use for to achieve what you're after:

Please note that none of the above plugins are compatible with Confluence 4.x.

Thank you!

Is there a user macro maybe, too?

Here's a macro to do it:

## Macro title: Macro Usage Report
## Developed by: Matthew J. Horn
## Date created: 11/12/13
## This macro takes no parameters
## @noparams

## Get a list of User Macros
#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($macroManager = $containerContext.getComponent('userMacroLibrary'))
#set($macroMetadataManager = $containerContext.getComponent('macroMetadataManager'))
#set($macroNames = $macroManager.getMacroNames())

## Get the ExcerptHelper (probably not supposed to be used for getting all macros, but it works)
#set($eHelper = $containerContext.getComponent('excerptHelper'))

## Get a list of pages in the space
#set ( $targetSpace = $spaceManager.getSpace("demo") )
#set ( $allPagesInSpace = $pageManager.getPages($targetSpace, true) )

## List all macro names
<h3>Macro names</h3>
<hr/>
#foreach($name in $macroNames)
  $name, 
#end

#set($isValid = false)

## Iterate over each page and check if each of the macros in macroNames is used on that page
<h3>Macro Usage</h3>
<hr/>
<table>
  <tr><th>Macro</th><th>Description</th><th>Page (isValid) (parameters)</th></tr>
  #foreach ($name in $macroNames) 
    <tr>
      <td>$macroMetadataManager.getMacroMetadataByName($name).getTitle().getKey() ($name)</td>
      <td>$macroMetadataManager.getMacroMetadataByName($name).getDescription().getKey()</td>
      <td>
      #foreach ($page in $allPagesInSpace)  ## $page is of type Page
        #if ($eHelper.getMacroDefinition($page, $name))
          <a href="$page.getUrlPath()">$page.getTitle()</a> ($eHelper.getMacroDefinition($page, $name).isValid()) ($eHelper.getMacroDefinition($page, $name).getParameters())<br/>          
        #end
      #end
      </td>
    </tr>
  #end
</table>

Hi Matthew,

thank you very much!

We tried and the Page column is empty. We set 'no macro body' - is it correct?

Rumi

The page column will be empty if there are no macros of that type in any of the pages. You're currently using "user macros" in the space that you're searching?

Hi Rumi,

if it is a specific user macro you are searching for, you can find it by its name. Simply search for:

macroName: <macroname>*

and replace <macroname> with the name of the macro you are searching for. Note that the capitalization, space after the colon, and the star at the end are all necessary.

More information can be found here: http://ffeathers.wordpress.com/2011/11/04/how-to-search-confluence-for-usage-of-a-macro/

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published yesterday in Confluence

Three common content challenges + how to manage them

An efficient enterprise content management system, or ECM, is a must-have for companies that create work online (cough   cough, all companies). If content calendars, marketing plans, and bu...

61 views 0 4
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you