Hi,
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.
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.
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What are you trying to accomplish with counting macros on the page?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So, are you trying to apply a unique id to user macros?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.