Within a Confluence macro, how do I retrieve the current ContentEntityObject?

Within a Confluence macro, how do I retrieve the current ContentEntityObject?

You can retrieve the current ContentEntityObject (ie the content object this macro is a part of), as follows:

public String execute(Map parameters, String body, RenderContext renderContext) throws MacroException {
    // retrieve a reference to the body object this macro is in
    if (!(renderContext instanceof PageContext))
    {
        throw new MacroException("This macro can only be used in a page");
    }
    ContentEntityObject contentObject = ((PageContext)renderContext).getEntity();
    ...

Note that this method might return null if there is no current content object (for example if you are previewing a page that has not been added yet, or if a remote user is rendering a fragment of notation).

Was this page helpful?

Have a question about this article?

See questions about this article

Powered by Confluence and Scroll Viewport