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/
Related
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
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/
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.
I want to have achieve something similar to Java Tiles framework using only client side technologies (no server side includes).
I would like to have one page, eg layout.html which will contain layout definition. Content placeholder in that page would be empty #content div tag.
I would like to have different content injected on that page based on url. Something like layout.html?content=main or layout.html?content=edit will display page with content replaced with main.html or edit.html.
The goal is to avoid duplicating code, even for layout, and to compose pages without server-side templating.
What approach would you suggest?
EDIT: I don't need a full templating library, just a way to compose a pages, similar for what tiles do.
JavaScriptMVC has a view templating system that supports different engines, including a pure JavaScript based one called EJS.
You might also want to look into Mustache especially Mustache for JavaScript.
If you would like to use jQuery, there is a decent templating engine in development as well:
http://github.com/jquery/jquery-tmpl
http://api.jquery.com/jquery.tmpl/
Check this out:
http://layout.jquery-dev.net/
I thinks it's close to what you want.
I am looking at javascriptMVC at the same time.
In the forum they are talking about using jquery layout with it.
I don't know if it fit exactly to what you want to do, but using the GWT seems to be a good approach for rich client-side applications :
You write all your application in Java with the framework, and you compile for obtain HTML and JS files working stand-alone.