Rendering to execute velocity?

Hello fellow xwikiers,

I’m trying to use $services.render($content, "xwiki/2.1") to render content provided within an XWiki object. It appears that rendering XWiki syntax works ok but velocity macros don’t get executed. Is there a secret flag to use for this? I assume that this may need some programming rights.

Alternatively, is there another way to request velocity execution with some regular xwiki context from within velocity or within java?

thanks in advance.

Hi @polx

AFAIK there’s no script service for applying transformations. The Script service API is at

Now you’ll need to use PR and get a Converter component:

The issue is that you won’t be able to create a printer in Velocity. Works in Groovy though.

I don’t know why we don’t have a rendering script service API to apply transformations. Maybe we have never needed it as this is usually done in java.

Well, this is getting a bit more confusing for me.
You mean Transformations in the sense of rendering transformations, right?

I was about to accept that only wiki rendering would be done until… I observed that the $services.rendering.render($xdom, 'xhtml/1.0') also doesn’t even resolve internationalization macros.

Let me try to detail my use-case, and maybe there’s something I can do. It can all be done in Java for me too but I am missing an example (what’s done in the Getting Started of rendering seems to be for a use case detached for XWiki and, in particular, may be missing context).

I am trying to allow “configuration objects” of “providers” to contain a piece of code. All such occurrences should be rendered within a page (with the HTML of the page).
So it seemed that the normal thing would be to store in java the source of the pieces of code and use velocity to render them. Some rendering should depend on the languages at least, hopefully other objects can be put in the velocity context so that the custom script can read this.

Where can I look for an example of such?

thanks in advance.



I don’t know what " internationalization macros" are but if they are rendering macros then this is implemented as a Macro Transformation and since Transformations are not executed by $services.rendering.render, it’s normal.

I have hard time understanding your use case but if all you wish to do is, from java, render some content with execution of transformations you should follow what’s on

As I mentioned already the Converter usage will execute transformations. You also have an explicit example on how to execute the transformations.

Hello Vincent,

It’s all good. I got convinced that using the Converter class is ok. It all appeared baked for the usage outside of XWiki so that I was reluctant to use this and expected to use “objects lying around that were already initialized”. It took me a while to test, but that’s because of me.

It does work very well and using this allows me to use the breadth of all thinkable XWiki-supported syntaxes which is cool.

cool! :slight_smile: