I'm trying to AJAXify some functionality of a page that uses Jinja2 and Flask. Problem is that I want the entire Jinja2 template to be rendered by Javascript but, this isn't possible with some of the available libraries as they don't support all the features of jinja2. What's the best way to solve this issue?
There seems to be https://github.com/syrusakbary/jsjinja library now:
JsJinja lets you use your Jinja2 templates in Javascript. It compile the Jinja2 templates to Javascript with no restrictions.
Not tried it though.
I've solved this same problem by writing Jasinja. It supports a fairly large subset of the Jinja template syntax.
There is Nunjucks by Mozilla, a templating engine in Javascript inspired by jinja2 that may suit your needs. https://mozilla.github.io/nunjucks/
Related
I'm looking for a front-end HTML templating engine and I was wondering if Vuejs has this functionally built into it. If not, can someone recommend me a templating engine?
All I want to do is create HTML pages which derived from a master page.
Thanks
I've used Mustache and have found it great - easy to use and fast. Check it out here: https://github.com/janl/mustache.js/
I'm totally new to js template engines. Handlebars seems to be the popular choice. I don't dislike the syntax for doing conditions, loops and so on, but since I'm perfectly capable of and feel more comfortable using plain old js and I'm not planning to let anyone who doesn't know js touch my templates, I'm asking if Handlebars supports this.
Of course the most popular choice isn't always the best. I'm more of a Mootools guy and jQuery drives me crazy(great library, just not for me). So if Handlebars was jQuery of template engines, what would be Mootools?
One of the central ideas behind handlebars and mustache is they are LOGICLESS by design and intention. They can not now, nor will they ever allow or recommend you embed raw JS in your templates. Some say this is a better design. If you want embedded javascript, almost every other traditional templating engine, such as _.template or jade or EJS is based on (or at least supports) the idea of embedded JS code snippets.
Sorry to resurrect a old issue here. If you have to use handlebars or it's not feasible to change your templating library you can use Helpers from the Handlebars library.
https://handlebarsjs.com/guide/expressions.html#helpers
Registering a helper in handlebar can be a walk around to what you are trying to do. See this link for a complete example: Registering handlebars helpers with node does absolutely nothing
currently I'm playing a little bit with spine.js
I have red the documentation about views and there they have shown an example with eco as templating engine.
Until now i don't really like the eco engine.
I would prefer to use haml as my templating engine.
Is there a way to add support for haml in spine.js?
Until now i tried to add https://github.com/uglyog/clientside-haml-js in my index.html and then i was able to compile haml templates, in my controller, to html.
But it is not possible to load the templates in the same way as it works wit the eco files.
So how can I integrate haml into spine.js?
Use hem-haml-coffee.
I recently added jhaml support as an equivalent to jeco.
The solution is to add a slug.js file to your application which includes the relevant stuff
You will find a more detailed solution here: https://groups.google.com/group/spinejs/browse_thread/thread/d951e77db33d084a
I'm trying to find an HTML templating solution that will work both on my ASP.NET MVC application (.NET 4, IIS 7.5) and in the browser. The reason is to the the same code to render HTML both on the server (performance, outputting to mobile, etc) or on the browser (refreshing data via AJAX). This is not a new problem, but I am wondering if current technology trends have changed the answer.
A couple of ideas I am considering:
Use mustache templates with are available in both
JavaScript and .NET.
Use a port of the Razor View Engine to
JavaScript like considered in Javascript + Razor == Jazor?.
Take a position like Micro Templates Are Dead... forget about it and
just use JavaScript (IronJS?) and the DOM (jsdom)
ASP.NET MVC View Engine Comparison looked relavent, but there is no mention of mustache.
Update: The client-side templating throwdown: mustache, handlebars, dust.js, and more from LinkedIn Engineering rates mustache in it's top four, with it being the only one with native .NET rendering (vs requiring server-side JavaScript to render on the server).
I would highly recommend mustache for your application. You have already mentioned abt the fact that it has a server side rendering engine and also a strong community backing. Apart from this the major reason why I would recommend mustache is for Performance of the templating engine. I have played around with the same and none of the other JS templating solution could match the performance of mustache.
What I would like more is documentation around the library but you should be able to work around this.
I have done that using Spark view engine, it is quite good with the template where you can use it from .net and js.
What of instead of the standard Django template rendering model which is server side, there were a library that allowed something that looked like a Django template to be rendered with JavaScript in the client's browser? The variables could be filled in by getting a JSON blob from the server and rendering the template would be done entirely on the client side.
Does a library like this already exist?
As I understand it, GWT sort of does this, but behind the scenes and with a ton of programmer overhead.
I think you may be thinking of the recently announced jQuery template plugins. There are of course other solutions out there, this has gotten the most press lately, with a similar syntax to what you describe.
Google Closure has a template library, there is TrimPath, and there is a long list of answers over here.
you probably think of mustache, but you can also check pure templates