Using Mustache for templating in 6.1

Enonic version: 6.1


We’re about to start a new website with Enonic XP (hooray), and we’re at a crossroads when it comes to choosing a templating library.

I’ve always been a huge fan of Mustache - so I was thinking of suggesting that for this project. However, there is just about no documentation about how to use it with Enonic. When is this planned?

Would you even suggest to use anything but Thymeleaf for the current version?

Best regards,


Hi Kristofer,

As far as I know Mustache for XP doesn’t support usage of “portal” functions directly in the view. You must “parse” that data in your controller before sending it as variables to your view. Perhaps not a big deal breaker (unless I’m missing something here).

In short we recommend thymeleaf for html, mustache for json and xslt for xml :slight_smile:

1 Like

Hi guys - thanks for the quick answers!

Compiling the URLs in the controller versus directly in the view is no big deal - it keeps the templates even cleaner.

@tsi - can you elaborate on why you make this recommendation?

It’s quite obvious:

  1. Thymeleaf is coded as HTML - specifically using html5 data attributes, so it is very good at producing html, less good at xml - and not in particular useful for producing JSON. The fact that any valid HTML5 page is also a valid thymeleaf template (and visa versa) speaks for itself - it is probalby the best server side HTML5 templating engine available.
  2. XSLT is coded in xml, using xml concepts such as namespaces etc etc. It also requires XML as input - and it is best at producing an XML as output too… (xhtml is xml too you know). No wonder Enonic CMS was good at producing high quality HTML all the way as it used xslt for everything. XSLT is a bit hard to learn, and not very suited for producing non-markup results
  3. Mustache is relying on JSON objects passed in, and is quite flexible at what it outputs - so given that Thymeleaf and XSLT both are are more specialized for their respective formats, Mustache is the obvious choice for JSON (and other output formats).

You can naturally also add your own templating language as a library to your project too, say freemarker if you like that. However, there might be some work getting the portal functions working - but I guess that’s optional?

Hope this was clearifying :smile:

Hi @tsi :smile:

Thanks for explaining - and getting back to me so quickly. Perhaps this kind of information should be available through the documentation? :blush:

Anyways, thanks for the info!

1 Like