How to get Space Key on xhtmelmacro progmmaticaly?


I tried but Throws to nullPointerExeption.

PageContextpageContext = (PageContext) renderContext;
        ContentEntityObject contentObject = ((PageContext) renderContext)

String key = "ds";
        key = pageContext.getSpaceKey();

Also this code below throw to same:

    public String execute(Map<String, String> params, String body, ConversionContext conversionContext) throws MacroExecutionException
            return execute(params, body, (RenderContext) null);
        catch (MacroException e)
            throw new MacroExecutionException(e);

I have no idea what you are trying to achieve with the provided source code. In case you want to get the space key as indicated in the title you can use conversionContext.getEntity as starting point. In case your macro is rendered on a page you can cast the returned ContentEntityObject to a Page and use getSpace().getSpaceKey().