Created
October 7, 2010 04:22
-
-
Save jboesch/614548 to your computer and use it in GitHub Desktop.
django workaround for jquery tmpl tags
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script id="person-tmpl-django" class="fix" type="text/x-jquery-tmpl"> | |
<div id="person-${user.id}" class="person"> | |
<strong>${user.name}</strong> | |
[[each(i, c) user.children]] | |
<div class="child">${c.child_name}</div> | |
[[/each]] | |
<span>${user.age}</span> | |
</div> | |
</script> | |
<script type="text/javascript"> | |
// Since jQuery tmpl uses the same tags as django {{ }}, we need to code it | |
// differently (square brackets) then run the replacements client-side to | |
// change it back so django won't pick it up. | |
$(function(){ | |
$("script.fix").each(function(){ | |
$(this).text($(this).text().replace(/\[\[/g, "{{").replace(/\]\]/g, "}}")); | |
}); | |
}); | |
// Make ajax request | |
$.post('json/add_person.json', { person: 'bob', age: 55 }, function(data){ | |
$.tmpl($('#person-tmpl-django'), data).appendTo('#people'); | |
}, 'json'); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment