Run macro only on create or edit

Hello everyone.
I want to achieve something like this, when user adds {{myMacro}}#BODY{{/myMacro}} to his page, I want to parse text inside tags (#BODY) and return some html in there, but the thing is, I wan’t to do this only when someone is editing or adding new page, not everytime the page is visited. Is it possible to achieve it using custom Macro?


Hi, yes, it’s possible and easy to do actually. In your wiki macro (see for a tutorial) you’ll just need to test for the context action.

For example:

#if ($xcontext.action == 'edit')
   ... do something...
   ... do something else...

Thank you for quick reply, but I don’t know if we are on the same page.
On ‘edit’ or ‘create’ I want to run macro and save some html produced by it, then on view i wan’t to display this html which was produced before.

So, when one types


And let’s say that myMacro reverse a string, then on page we will see:


But i wam’t myMacro function to run only once(while creating), not everytime someone is accessing page.

Ok so indeed we were not talking about the same thing at all :slight_smile:

You cannot really use macros for your need.

What I think would be better:

You can write your listener as a wiki component or as a java component (recommended).

Hope it helps

1 Like

Awesome, thank you for your help!