Twig Template Engine

Reading this post I was a bit interested on applying another template engines and that was a surprise for me that this could be made without using java. I’ve implemented Twig using TwigJS library with success needing few small changes. This is really nice, since in my company the projects are in Enonic or eZ Publish, developers prefer this instead of Thymeleaf.
As result, I have a page that in full thymeleaf lasts 4.000ms to load and 2.800ms in Twig (40% faster to render the same page!).

For anyone that gets interested, I had to:

  • put “twig”, “path” and “fs” (npm packages) on the lib folder;
  • rename the “path.js” file to “index.js”;
  • include in the controller and use it.

:slight_smile:

4 Likes

Nice!
Have you thought about making a starter project with Twig?
I think that could be useful for your own company and for others.

1 Like

Did you try XP 6.6 it has the upgraded version 3 of thymeleaf. It is supposed to be faster. Would be interesting to see if it improves speed on your usecase?

Also, a twig library sounds cool :slight_smile:

1 Like

Nice, please consider creating a twig.js library for Enonic XP. Would be really nice!

1 Like

@aro, @tsi, @srs thanks for the responses.I’ll talk to the guys here about creating a starter for it :slight_smile: I think should be useful for everyone too. About enonic version, it was on 6.6.

Hi. It’s better to create a lib. A starter-kit is more for the build part of it (grunt, gulp, es6).

1 Like

This is really cool!! I have a few questions, though.

fs is not an npm package, it comes with the Node binary. Did you pull it directly from Node’s source code to add it to the lib folder, or did you add some other npm package?

path uses the process object, which is also not available in Nashorn (as far as I know anyway). You mention that you only had to rename the file to index.js, but this should result in an error. Did you modify the source to get things working, or am I missing something here?

No, I hadn’t to change source code. I’ve just executed “npm install path” and “npm install fs”, so I get these packages, even if they are already in Node Installation. The downloaded packages on node_modules were then moved to the lib folder and after the changes I described here they were working :smiley:

1 Like

Hi @PVMerio,

How are you doing? Can we expect to see a lib for market? :slight_smile:

Ops! Of course! I’ll send as soon as possible :slight_smile:

2 Likes

Any news about the Twig lib, @PVMerlo?

Sorry, not for now. I’m envolved with another projects, but as soon as possible I’ll return the work on this lib.

1 Like