Search code examples
jquerydjangodjango-templatesjquery-templates

jquery template tags conflict with Django template!


Today I'm trying to play with jquery-tmpl {{if}} & {{else}} statements.

<script id="mission-dialog" type="text/x-jquery-tmpl">
    <h3>${name}</h3>
    <p>${description}</p>
    <ul>
        {{each(i,cond) conditions.data}}
        <li>
            <img src="${cond.image}"/>
            <h4>${cond.name}</h4>
            <p class="status">${cond.status.value}/${cond.status.max}</p>
        </li>
        {{/each}}
    </ul>
</script>

But as you know {{ }} is reserved also for django template. So django will emit TemplateSyntaxError that it can't parse it.

How can I solve this problem?


updated:

I found a working <% raw %> custom tag (GPL) implementation from here.

http://www.holovaty.com/writing/django-two-phased-rendering/


Solution

  • Use the templatetag template tag to render the brackets:

    {% templatetag openvariable %}each(i,cond) conditions.data{% templatetag closevariable %}
    

    It's a bit fiddly, which is why a raw template tag has been proposed for Django 1.3.