Skip to content

Allow customizing template tags format #74

Open
secha opened this Issue Feb 17, 2011 · 7 comments

5 participants

@secha
secha commented Feb 17, 2011

The Tmpl plugin doesn't work on Modx CMS. Modx users the double '{' for Chunks which are HTML block's of code. So when we try to use:

{{if 1=1}}

Modx will try to search for 'if 1=1' chunk in the database, he find's nothing so he just deletes the fragment.
It could be a good thing to try and put the '{{' into some kind of option that would allow to change it.

@BorisMoore
Owner

Yes, this is planned for a later version.
Changing title to correspond to issue above.

See: the following copied from http://github.com/nje/jquery-tmpl/issues#issue/17 on nje/jquery-tmpl:

Currently the templatetags use curly braces, which is cool but clashes with other templating languages such as Django's. In this case, Django tries to interpret all the text included within {{ }} as if it was a Django templatetag, which ends up being a syntax error and the page can't be rendered.

As Django currently doesn't provide a clean way to escape those variables, it would be nice to be able to define the tag used for templatetags in jquery-tmpl. Other JS templating libraries such as jQote2 have this option

Comments
BorisMoore September 07, 2010
I'll note that as a feature request. Not sure when we will add that support. For now can you get Django to render the {{ and/or }}, rather than including them as literals, so that you no longer parse on the server as a template tag? On an ASP.NET Web form, for example one might do:

<% Response.Write("{{"); %>if foo}}

rather than

{{if foo}}

.

julen September 07, 2010
With Django you can achieve that with the templatetag templatetag. You'll end up with code like this:

{% templatetag openvariable %}if foo{% templatetag closevariable %}
That's ugly and unreadable IMHO.

For now as a workaround I'm using square brackets and replacing them when the document is ready. So basically the replacement code looks like this:

$(document).ready(function() {
  var newtext = $("script#my_template").text().replace(/\[\[/g, "{{").replace(/\]\]/g, "}}");
  $("script#my_template").text(newtext);
});

And in the template code I use:

[[if foo]]

Which is quite more readable than before.

Anyway, it would be great if jquery-tmpl could allow customizing the syntax used for the tags.

BorisMoore September 07, 2010
Understood. I'll consider that feature request, but will need to look into whether it can be achieved with minimal additional code and without creating a big additional test matrix. (Like, for example, that some choices of the tag characters can conflict with other constructs.)

limist September 30, 2010
Another hand-up for custom syntax for templating tags please, as currently jquery-tmpl will bite all Django users.

chodorowicz October 05, 2010
another vote from me! would be great to customize this syntax

chrisdew October 05, 2010
+1

jboesch October 06, 2010
+1 this sucks for django :(

timmolendijk October 10, 2010
Showstopper, so +1

BorisMoore October 10, 2010
I am sure we will address this. Votes and scenario noted. Just not sure of the timeline yet.

timc3 October 14, 2010
Another +1

fitzgen October 20, 2010
Just use a custom template tag in Django to include templates "raw" without parsing the template syntax: http://djangosnippets.org/snippets/1684/

I wrote that template tag for my old JS templating engine, Tempest, which used syntax very similar to Django's templating language as well.

In your Django template that will create the page with the javascript, just do something like:

<script id="my-template" type="text/x-template">
  {% include_raw "myapp/mytemplate.html" %}
</script>
<script type="text/javascript">
  var myTemplate = $("#my-template").html();
  // etc...
</script>

colinsullivan October 24, 2010
fitzgen:

I've got the snippet being recognized by putting it in: myapp/templatetags/extra_template_tags.py
then at the top of the template, putting
{% load extra_template_tags %}

However, the template cannot be found. I receive a "TemplateDoesNotExist" error. The template path is correct, because there are other templates in the same folder that are working.

Do you have an example usage?

EDIT:
Figured it out.

Top of template:

{% load extra_template_tags %}

Usage:

{% include_raw "../templates/collections/user_collection_template.html" %} ( path to template relative to your extra_template_tags.py file )

julen October 28, 2010
Just a quick note to say that the workaround used in http://github.com/nje/jquery-tmpl/issues#issue/17/comment/393931 doesn't work on IE.

colinsullivan November 05, 2010
This workaround also doesn't solve the problem of using a template for both Django and jQuery.

1stvamp November 17, 2010
This isn't a fix, just a workaround, and it won't help if you want to dynamically generate the template for jquery-tmpl.

BorisMoore November 17, 2010
At any rate, I absolutely agree with everyone who has requested a real fix for this. We will definitely provide one as soon as we can...

chrisdew November 25, 2010
I use Django's ssi tag as a work-around. It does require that I keep my jquery templates in separate files from the django templates, but it's not the end of the world. (I don't need to dynamically generate the jquery templates for my site.)

{% ssi /srv/my_site/templates/my_app/my_page.x-jquery-tmpl %}

See http://docs.djangoproject.com/en/dev/ref/templates/builtins/#ssi and http://docs.djangoproject.com/en/dev/ref/settings/#std:setting-ALLOWED_INCLUDE_ROOTS for more information.

@colinsullivan

Just to elaborate, I started using the {% verbatim %} tag for Django, which i thought was mentioned here but apparently is not.

You can find it here:
https://gist.github.com/629508

The ssi tag works if you do not want any server-side logic in the generation of your template, but you can use the {% verbatim %} tag if you want to generate some parts of a client-side template using a Django template.

@kof
kof commented Mar 15, 2011

@BorisMore I like this Idea with "verbatim" tag which will say tmpl engine to ignore all tags inside of it, do you want to implement it?

@BorisMoore
Owner

Yes, we could consider adding that tag. Do you want to create a new issue on that as a feature request? Obviously relevant to running jQuery templates on the server, but could be respected client-side too.

@kof
kof commented Mar 16, 2011

sure, thanks

@kof
kof commented Mar 16, 2011

#90

@rdworth
rdworth commented Oct 8, 2011

Thanks for taking the time to submit this issue. Just wanted to let you know this plugin is no longer being actively developed or maintained by the jQuery team. See README for more info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.