Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handlebars.js in Django templates

I need a javascript templating system and i think handlebars.js does an excellent job in this case. I'm having syntax conflicts with handlebars templates inside a django template because django tries to render handlebars variables.

Is there a tag in django templates to stop rendering a block with curly braces?

Something like:

{{ django_context_varable }} #works {{% raw %}} <script id="restaurants-tpl" type="text/x-handlebars-template">     <ul>     {{#restaurants}} #not rendered by django, plain text     <li>{{name}}</li>     {{/restaurants}}     </ul> </script> {{% endraw %}} 

Edit

Likely i found this. It works fine.

Update

Django 1.5 supports verbatim tag natively.

like image 379
tsiokos Avatar asked Aug 29 '11 11:08

tsiokos


1 Answers

I use a custom template tag for another js templating system, here: https://gist.github.com/629508

Use in template:

{% load mytags %} {% verbatim %}   {{ This won't be touched by {% django's %} template system }} {% endverbatim %} 

Edit: This custom template tag is no longer necessary, as Django's template language now supports the {% verbatim %} template tag.

like image 150
rych Avatar answered Oct 07 '22 11:10

rych