Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery template tags conflict with Django template!

Tags:

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/

like image 591
Ray Yun Avatar asked Oct 26 '10 08:10

Ray Yun


2 Answers

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.

like image 107
Daniel Roseman Avatar answered Oct 27 '22 17:10

Daniel Roseman


There are a few solutions mentioned here:

https://github.com/nje/jquery-tmpl/issues#issue/17 - Edit: Old repo

https://github.com/jquery/jquery-tmpl/issues/#issue/74

My favorite is the {% verbatim %} template tag that allows you to build jQuery templates from within Django ones.

like image 33
Colin Sullivan Avatar answered Oct 27 '22 16:10

Colin Sullivan