Forums

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

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

Rumceisz
Contributor
June 14, 2012

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

1 vote
Answer accepted
HuseinA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 14, 2012

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.

Rumceisz
Contributor
June 14, 2012

Thank you!

Is there a user macro maybe, too?

0 votes
Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 3, 2013

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/

0 votes
Matthew J. Horn
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 11, 2013

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
&lt;h3&gt;Macro names&lt;/h3&gt;
&lt;hr/&gt;
#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
&lt;h3&gt;Macro Usage&lt;/h3&gt;
&lt;hr/&gt;
&lt;table&gt;
  &lt;tr&gt;&lt;th&gt;Macro&lt;/th&gt;&lt;th&gt;Description&lt;/th&gt;&lt;th&gt;Page (isValid) (parameters)&lt;/th&gt;&lt;/tr&gt;
  #foreach ($name in $macroNames) 
    &lt;tr&gt;
      &lt;td&gt;$macroMetadataManager.getMacroMetadataByName($name).getTitle().getKey() ($name)&lt;/td&gt;
      &lt;td&gt;$macroMetadataManager.getMacroMetadataByName($name).getDescription().getKey()&lt;/td&gt;
      &lt;td&gt;
      #foreach ($page in $allPagesInSpace)  ## $page is of type Page
        #if ($eHelper.getMacroDefinition($page, $name))
          &lt;a href="$page.getUrlPath()"&gt;$page.getTitle()&lt;/a&gt; ($eHelper.getMacroDefinition($page, $name).isValid()) ($eHelper.getMacroDefinition($page, $name).getParameters())&lt;br/&gt;          
        #end
      #end
      &lt;/td&gt;
    &lt;/tr&gt;
  #end
&lt;/table&gt;

Rumceisz
Contributor
December 2, 2013

Hi Matthew,

thank you very much!

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

Rumi

Matthew J. Horn
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 3, 2013

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?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events