I'm trying to write a User Macro in which an HTML button triggers a javascript function, which in turn executes a Confluence macro.
I can get a macro (e.g. "I Like Cheese!") to execute just fine if placed directly in the HTML. For example, the following works fine:
<!DOCTYPE html> <html><head></head> <body> <p><div><ac:structured-macro ac:name="cheese"/></div></p> </body></html>
I can also successfully inject HTML with a button press. For example, the following works fine:
<!DOCTYPE html> <html><head></head> <body> <button onclick="runScript()">Insert HTML From Script</button> <p><div id="result"></div></p> <script type="text/javascript"> function runScript() { document.getElementById('result').innerHTML = '<b>Some bold text.</b>' }; </script> </body></html>
BUT, when I try to inject HTML for the macro, it DOESN'T work. The following does not work:
<!DOCTYPE html> <html><head></head> <body> <button onclick="runScript()">Execute Macro From Script</button> <p><div id="result"></div></p> <script type="text/javascript"> function runScript() { document.getElementById('result').innerHTML = '<ac:structured-macro ac:name="cheese"/>' }; </script> </body></html>
Can anyone spot why the first two cases work, but the 3rd does not?
Any feedback/advice much appreciated!
Community moderators have prevented the ability to post new answers.
Thanks Volodymyr.
I think I managed to get it working by injecting a call to the macro using $action.getHelper().renderConfluenceMacro(), rather than the HTML. The following appears to work:
<!DOCTYPE html> <html><head></head> <body> <button onclick="runScript()">Execute Macro From Script</button> <p><div id="result"></div></p> <script type="text/javascript"> function runScript() { document.getElementById('result').innerHTML = '$action.getHelper().renderConfluenceMacro("{cheese}")' }; </script> </body></html>
QUESTION:
Is there a problem with using $action.getHelper().renderConfluenceMacro() to call macros from within other macros, instead of using the <ac:structured-macro> markup?
Mac-roses are rendered on server so adding a macro tag via JavaScript has no effect.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.