Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

including handlebars templates within a django generated page

I am using django to serve a page that includes a handlebars template. Mixing server and client side templating creates some ambiguity. If I have a template

<script id="my-script" type="text/x-handlebars-template">
    <p> {{clientSideContent}} </p>
</script>

How can I tell the django templating engine that the {{clientSideContent}} tag isn't intended for it (since django and handlebars use the same tags)? Is there a raw strings tag in django, or an alternate good way to address this?

like image 210
BostonJohn Avatar asked Dec 01 '25 14:12

BostonJohn


2 Answers

I think this should solve your problem

https://gist.github.com/ericflo/629508

so use something like

{% verbatim %} {{clientSideContent}} {% endverbatim %}
like image 180
collend Avatar answered Dec 03 '25 04:12

collend


Never versions of django (starting from version 1.5) have support for the {% verbatim %} tag:

So something like this should work:

<script id="my-script" type="text/x-handlebars-template">
  {% verbatim %}
  <p> {{clientSideContent}} </p>
  {% endverbatim %}
</script>

Hope it helps.

like image 25
intuitivepixel Avatar answered Dec 03 '25 04:12

intuitivepixel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!