How to enforce the output syntax when rendering a UI extension

Hi everyone,

Many of our UI extension points use a code like this to render their extensions in a specified output syntax:

#foreach($uix in $services.uix.getExtensions('org.xwiki.platform.attachment.actions'))
  $services.rendering.render($uix.execute(), 'html/5.0')
#end

We sometimes pass “xhtml/1.0” as output syntax, but the principle is the same. The problem with this is that the UI extension is actually executed without taking into account the specified output syntax (‘html/5.0’ or ‘xhtml/1.0’). We execute it first, using the output/target syntax from the rendering context, which is influenced by the outputSyntax request parameter, and then we render it to the specified output syntax. This means that a template-based or wiki-based UI extension that produces a RawBlock will have no output when rendered on a page with ?outputSyntax=plain in the URL. This causes Loading... , because the PDF sheet is loaded with outputSyntax=plain and the sheet renders htmlheader.vm / meta.vm which execute org.xwiki.platform.html.head UI extensions. These UI extensions produce no output on PDF export.

Possible solutions:

  • quick fix: each UI extension that is in this case can specify ##!raw.syntax=html/5.0 in its template
  • better fix: introduce a new API to execute + render a UI extension to a specified output syntax, something like $services.uix.render($uix, 'html/5.0')

WDYT?

Thanks,
Marius

Note that the {{uiextensions}} and {{uiextension}} macros should not have this problem. But yes, it does not help much in the case of Velocity based templates.

Sounds good. It’s also a lot easier to use, so people will be tempted to use that.

Might also worth adding a helper like $services.uix.renderExtensions('org.xwiki.platform.attachment.actions', 'html/5.0') which seems to be a pretty common use case in templates.

Sounds good. I added both, plus a signature that allows passing filters.