2011/5/27 Gábor Farkas <ga...@nekomancer.net>: > On Fri, May 27, 2011 at 7:04 AM, Sean O'Connor <s...@seanoc.com> wrote: >> A better approach would for Django to provide some tools and documentation >> to help people work around the conflict. One easy solution would be to >> provide a verbatim tag like what ericflo wrote >> at https://gist.github.com/629508. Another would be to provide >> documentation on tools that make it easy to load jquery style templates via >> ajax like icanhaz.js. > > (technically, there is an open jquery-templating ticket about making > the template-tag format customizable: > https://github.com/jquery/jquery-tmpl/issues/74) > > i had the same problem in the past (btw. mustache.js also uses the > two-curly-braces notation :-), > and unfortunately the verbatim tag did not solve the problem, because > sometimes you need > to use the django-templating INSIDE the jquery template > . > for example: > """ > . > . > <script type="text/x-jquery-tmpl"> > Are you sure to delete {{ name_of_thing }}? > <button>{% trans "YES"%}</button> > <button>{% trans "NO"%}</button> > </script> > """ > > here i want the {{ name_of_thing }} to be handled by > jquery-templating, but the translation > should happen using the django-tags. > > so either i have to use the {% verbatim %} tag only around the places > where i have javascript-variables > (and not around the whole jquery-template), or i have to do the > translation in python, > and send them in as variables in javascript. both seem to be impractical. > > the approach i chose was to use a different variable-syntax > (instead of "{{ thing }}", i use "[[ thing ]]"), and before using the > template, > i simply replace those with the correct values. it's not nice, but > still the most practical solution i could find. > > gabor
I wonder if verbatim as a filter makes more sense, for example:: <script type="text/x-jquery-tmpl"> Are you sure to delete {{ "{{ name_of_thing }}"|verbatim }}? <button>{% trans "YES"%}</button> <button>{% trans "NO"%}</button> </script> The filter would then just return {{ name_of_thing }} back to the template. If you wanted to use a template variable as the name of the jQuery variable this approach would still fail. Now that I think about it maybe the replace tokens approach is the most flexible. {% verbatim "[[" "]]" %} <script type="text/x-jquery-tmpl"> Are you sure to delete [[ name_of_thing ]]? <button>{% trans "YES"%}</button> <button>{% trans "NO"%}</button> </script> {% endverbatim %} You you could then choose the tokens that get replaced. - Sean > -- > You received this message because you are subscribed to the Google Groups > "Django developers" group. > To post to this group, send email to django-developers@googlegroups.com. > To unsubscribe from this group, send email to > django-developers+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-developers?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.