Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting TemplateSyntaxError: unexpected char u'#' on including a Mustache template in html file served by python Google App Engine

I am getting a TemplateSyntaxError: unexpected char u'#' error, when I include a simple Mustache template in my HTML file being served by Python Google App Engine server.

The mustache template that I want to include is:

{{#item}} {{name}} {{/item}}

My HTML file looks like this:

<!DOCTYPE html>
<html>
  <head>
    <script type="text/mustache-template" id="myTemplate">
      {{#item}}{{name}}{{/item}}
    </script>
  </head>
</html>

Since, the template is wrapped around a script tag with type=text/mustache-template, shouldn't the server just ignore it?

I am unable to comprehend, why am I getting the TemplateSyntaxError and what should I do to get rid of it. Anyone has any ideas? Thanks!

like image 509
Nikhil Jindal Avatar asked Jan 05 '14 11:01

Nikhil Jindal


1 Answers

You don't say so, but I guess you are using either Django or Jinja2 templates on the server side. In which case, no they wouldn't ignore content inside a mustache script tag: for one thing, they know nothing about mustache, and secondly it's fairly common practice to actually put server-side template tags inside Javascript, for instance to provide initial values for functions.

In Django versions greater than 1.5, you can wrap your mustache tags with the {% verbatim %}...{% endverbatim %} tag to prevent server-side evaluation. Jinja2's equivalent is {% raw %}...{% endraw %}.

like image 105
Daniel Roseman Avatar answered Nov 01 '22 17:11

Daniel Roseman