Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you use two HTML templates such as Handlebars and Jinja

I'm trying to write an app in javascript with the ember.js library which relies heavily on the Handlebars templating system. However, I'm using FLASK which also uses the jinja templating system.

Is it possible to use both template renderers at the same time? Or do I need to use one over another. Anyone with experience using both flask and ember.js know which one would potentially be easier to replace with the other?(Maybe handlebars is much easier to replace Jinja with or vice versa).

like image 943
bhuj2000 Avatar asked Jun 26 '13 18:06

bhuj2000


2 Answers

Note that these two template engines are in different places. Jinja2 will run on the server side, Handlebars will run on the client side. You could potentially use both without interference if you needed to.

But with that said, there is really no need to use server-side templates if you have a rich client framework like ember.js. In your situation the Flask server will likely have routes that serve data via ajax requests back to the ember.js client, so the client is really the best place for template rendering to happen.

like image 136
Miguel Avatar answered Oct 02 '22 15:10

Miguel


You can mark sections of code as {% raw %} to tell jinja2 to ignore it. Wrap your handlebars.js template in raw tags like so:

{% raw %}
<script id="foo-template" type="text/x-handlebars-template">
    <p>{{foo}} - {{bar}}</p>
</script>
{% endraw %}
like image 35
Mark Simpson Avatar answered Oct 02 '22 17:10

Mark Simpson