New script APIs to execute and render UI extensions
A common pattern for rendering UI extensions using scripting (Velocity) is:
#foreach($uix in $services.uix.getExtensions("org.xwiki.platform.html.head", {'sortByParameter' : 'order'}))
$services.rendering.render($uix.execute(), 'html/5.0')
#endThe problem with this is that the specified output syntax, html/5.0, is not taken into account when executing the UI extension. It is used only to control how the result of the execution is rendered. This may seem enough, but when a template-based or wiki-based UI extension produces a raw block, this is labeled with the syntax from the rendering context, which is not necessarily the target syntax specified by the script (e.g. when the page holding the script is accessed with ?outputSyntax=plain). Such a UI extension can thus be excluded from the output because an HTML renderer will ignore non-HTML raw blocks (same as a plain text renderer will ignore HTML raw blocks).
This problem doesn't manifest when using {{uiextension}} or {{uiextensions}} macros, which is why we recommend using them when wiki syntax is available. But we still have a lot of UI extension points in Velocity-only templates. For this we introduced the following new script service APIs to execute and render UI extensions in a given syntax:
$services.uix.render($uix, 'html/5.0')
$services.uix.renderExtensions('org.xwiki.platform.template.header.after', 'html/5.0')
$services.uix.renderExtensions('org.xwiki.platform.html.head', 'html/5.0', {'sortByParameter': 'order'})Checkout the documentation for more information.