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

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • 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

How many macros in a page? Edited


I am creating a user macro and would like to count how many times a specific macro is present in a page. Is there a way to accomplish this using Velocity?

Thank you.

2 answers

0 votes
Davin Studer Community Leader Oct 10, 2019

What are you trying to accomplish with counting macros on the page?

Hi Davin,

I would like to differentiate the element ID of the HTML container by using an increment on it before the page was rendered at the client side, something like id="macro-1", id="macro-2", etc.

I can do it at the client side via Javascript but would like to see if I could render the page already with the proper number in the ID. I managed to identify the macro I wish in a page but not to count how many instances of it exist.

Thank you.

Davin Studer Community Leader Oct 14, 2019

So, are you trying to apply a unique id to user macros?

Hi Vitor,

it’s certainly possible, you can read the storage format, which is just xhtml, and each macro is defined by an <ac:macro> element. You would have to treat it as a string, though, no DOM operations would be available in a user macro.

However, the biggest problem is that the xhtml element is “translated” by Confluence into regular html code during the final page rendering process. A user macro has no access to this final html code. So, if you added an id to the macro element, it would just be ignored. The best you could do would be to wrap the macro in a div element and assign an id to that.

It’s a bit long of an answer, but I hope it makes sense.

Hi Stephen,

Thank you for your help but I am not quite sure if your answer covers exactly what I'm looking for (very likely because my post was very, very vague)...

The macro I created for test purposes is using a <div id="macro-${macroNumber}">... I would like to to confirm the existence of macros with the same name in the page, how many and then assign n+1 to $macroNumber, being n the number of macros found.


Suggest an answer

Log in or Sign up to answer
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...

342 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