I really like django/jinja2 templating languages. Their syntax is extremely simple and yet is highly versatile. Is there anything similar to that in both syntax and capability in javascript, or if not both, at least in the capability.
I looked at underscore, jquery templates, and mustache templates, and none of them seemed to be what I am looking for.
Additional notes
I think out of all libs (I looked at) mustache is the best but I don't really like the syntax. For example this mustache template
{{#people}}
{{name}}
{{/people}}
{{^people}}
No people :(
{{/people}}
compared to django's templates:
{% for person in people %}
{{ person.name }}
{% empty %}
No people :(
{% endfor %}`
Also the same thing for applying filters. For example:
{{#filter}}{{value}}{{/filter}}
vs
{{ value|filter }}
I think django/jinja2 approach is more clean and just feels more natural.
So, is there any js library which does templates very similar to django/jinja? If not, I guess I have to live with muschache (or maybe some other good js library - I am open to suggesstions), but it just doesn't feel right.
Thank you.
Jinja is one of the most used template engines for Python. This project is a JavaScript implementation with emphasis on simplicity and performance, compiling templates into readable JavaScript that minifies well.
Jinja, also commonly referred to as "Jinja2" to specify the newest release version, is a Python template engine used to create HTML, XML or other markup formats that are returned to the user via an HTTP response.
Jinja is a web template engine for the Python programming language. It was created by Armin Ronacher and is licensed under a BSD License. Jinja is similar to the Django template engine but provides Python-like expressions while ensuring that the templates are evaluated in a sandbox.
Have a look at Nunjucks, a JS templating engine heavily inspired by Jinja2. It supports block inheritance, macros, filters and much more and works both server (NodeJS) and client-side (most browsers).
My JavaScript Jinja implementation can be found here: https://github.com/sstur/jinja
It supports both Jinja and Liquid syntax, runs on the browser and in Node, will compile templates to dependency-free JavaScript, and is about 3K gzipped
http://sstur.com/jinja/demo/
Tests included. Express.js support in progress..
Link from @pradeek's comment. It is a port of jinja to js.
https://github.com/ericclemmons/jinja.js
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With