Thymol as a template engine for Backbone

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Thymol as a template engine for Backbone

wortas
Hi, I like the Thymol project. I'm using thymeleaf in the backend and it will be nice to utilize it also in frontend. I will be nice to have thymol to replace BackboneJS's Templating engine. Any hints how to do such a integation? I suppose it must be done on BackboneJS level. Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Thymol as a template engine for Backbone

jjbenson
Administrator
Hi Wortas,

  Using Thymol in conjunction with Thymeleaf 2.X should be easy, all you should have to do is to take care with the namespaces.

  It would be easiest if you use one namespace for attributes that should be processed by Thymeleaf and another for those to be processed by Thymol.

  If you're using XHTML, simply set the value of thPrefix accordingly. If you're using HTML5-style attributes, use an appropriate combination of values for thPrefix and thDataPrefix.

  I must admit to knowing very little about Backbone, but it appears that the out-of-the-box system uses Underscore's templating facilities and excluding Underscore isn't an option as it's a required dependency.

  Also, Thymol is usually used so that it instantiates templates implicitly as it parses and processes Thymeleaf/Thymol attributes within a template hierarchy.

  Currently there is no API for instantiating (Thymol) templates explicitly as Backbone does.

  So I don't think you'll be able to replace Backbone's templating system with Thymol as such.

  Having said that, I don't think there is anything stop you from using Thymol "as-is", using Backbone and Underscore similarly, and creating any JavaScript "glue" you might need as you go.

  You may however encounter problems with order of loading and/or processing.

  My advice is to create a simple prototype, use the usual Thymol script load, add a data-thymol-load script to set things up and early in that script call "ThUtils.loadScript(<script url>)" for underscore.js and backbone.js. Then proceed to define a simple example using the most basic constructs, and see how they hang together.

  Please post back your findings, I will help with any problems you come across as best I can.

  Regards,

    Jim
Reply | Threaded
Open this post in threaded view
|

Re: Thymol as a template engine for Backbone

wortas
Thank you I really appreciate your answer. I will try to get back, if I will find any reasonable solution.

Regards

Martin
Reply | Threaded
Open this post in threaded view
|

Re: Thymol as a template engine for Backbone

jjbenson
Administrator
Hi Martin,

  I've added a small enhancement on the master branch of the Thymol repo that might make things easier for dual Thymeleaf/Thymol processing:

  You can now use separate XML namespace declarations in the style: "xmlns:<thymol-prefix>=http://www.thymoljs.org" and "xmlns:<thymeleaf-prefix>=http://www.thymeleaf.org".

  This should allow you to define a Thymol-specific prefix without any additional JavaScript code.

  (For the moment) you can find a snapshot build of the new code here: https://github.com/thymol/thymol.js/tree/2.x-master/sourceforge

  Regards,

    Jim