Insert multiple macros at once

Is it possible to programmatically insert multiple macros at once, for example inserting a Macro with a body of multiple other macros?
Or even better: Insert multiple macros after the current macro?

Thanks and best regards.

1 Like

Yup, you can insert a macro programmatically at the current cursor position. To insert multiple macros you can execute the according command multiple times obviously. Insert a macro inside a macro could be a bit tricky as I’m not sure if the “body” attribute you see in the example below supports anything else but HTML. But “insertMacro” inserts the macro where the cursor is. So I would try to change the tinyMCE cursor position to point inside the target macro body and then use the command.

// execute this in global JS scope, not inside the editors iFrame
const params = {
    background: "#c3cd2d",
    foo: "bar"
}
const macroRenderRequest = {
    contentId: Confluence.Editor.getContentId(),
    macro: {
        name: "some-macro-key",
        params,
        body: "<p> some body </p>"
    }
};
tinymce.confluence.MacroUtils.insertMacro(macroRenderRequest);
tinymce.confluence.MacroUtils.insertMacro(macroRenderRequest); // do it multiple times, maybe change cursor before to insert content inside the macro
tinymce.confluence.MacroUtils.insertMacro(macroRenderRequest);```
2 Likes