Macro content can be declared to be inline editable
Some part of the macro content can be declared as inline editable: the user will then be able to edit those parts of the content directly in the wysiwyg editor.
In order to make this available you need to specify 2 information when declaring the macro:
- the type of the macro content
- the parts of the macro that can be editable inline
Specify the type of the macro content
You need to specify it in the constructor of the DefaultContentDescriptor:
The type of a content which can be editable inline, is List<Block>.
In order to simplify its declaration, we created a constant that can be immediately used:
Specify the parts of the macro that can be editable inline
When declaring the result of the macro by overridding execute method, you can specify which parts of the macro will be editable inline, by specifying some metadata.
For example, if you want to declare a block containing a logo which is always the same and a block which will be editable inline you can specify it like that:
Block logoBlock = new ImageBlock(imageReference, true);
List<Block> content = this.contentParser.parse(content, context, false, context.isInline()).getChildren(); // parse the existing content and get its children blocks
Block editableContent = new MetadataBlock(content, this.getNonGeneratedContentMetadata()); // specify the right metadata in order to make the content editable inline
return Arrays.asList(logoBlock, editableContent);
The obtained result for the rendering will look like:
<span id="logo"><img src="mylogo.png" /></span>
<div data-xwiki-non-generated-content="java.util.List< org.xwiki.rendering.block.Block >" class="xwiki-metadata-container">
<p>my editable content</p>
</div>
<!--stopmacro-->
The syntax used inside the editable part can be declared by using a syntax metadata.
Consider that nested macro will be editable inline, only if they also declare an editable content. On the same idea, if a nested macro declare an editable content, it can be used only if the parent macro also declare an editable content.