#2181 closed enhancement (fixed)
[patch] templatetag should do openbrace, closebrace
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Template system | Version: | |
Severity: | normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The templatetag tag system isn't quite enough in some situations. For example, there are problems when templating a LaTeX file. There is a LaTeX command of the form \includegraphics{myfilename.jpg}. Unfortunately,
\includegraphics{{{ filename
}}} is a syntax error in the templating system, so it's difficult to specify a filename to be filled in, especially since \includegraphics{ myfilename.jpg } is illegal in LaTeX (extra spaces aren't allowed). I would recommend adding {% templatetag openbrace %} and {% templatetag closebrace %} to the already existing templatetag to allow escaping in this situation.
Attachments (4)
Change History (13)
comment:1 by , 19 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 by , 19 years ago
Resolution: | invalid |
---|---|
Status: | closed → reopened |
That's a way to do it, but from my perspective as a user, it's an awkward solution. If I expected to do a lot of includegraphics commands, making a template tag would be a natural way to go. However, in an isolated case like this, where the real issue is escaping special characters, it would feel much more natural use templatetag.
I guess it might also be helpful if the template parser only looked at the innermost two braces in a string of braces, i.e. in the string {{{{{
the first three braces would be assumed to be part of the text. Right now the first two braces are considered to be the escape string, and the innermost three braces are considered part of the variable name, which is illegal syntax anyway.
Anyway, those are my thoughts.
comment:3 by , 19 years ago
Resolution: | → wontfix |
---|---|
Status: | reopened → closed |
Sorry, embedding variable template tags within block template tags is too ugly and unintuitive. Just write a custom template tag like I suggested -- it's easy and fun.
comment:4 by , 19 years ago
Resolution: | wontfix |
---|---|
Status: | closed → reopened |
Whoa. I think I completely failed to communicate what the issue is.
All I want to do is put a curly brace next to a variable template tag! It takes me a half a screen of code to write a custom template tag, and it's all just to print one stupid little curly brace!
I've been really impressed with everything else in Django. I really like it a lot. But I can't justify writing half a screen of code, just to get one little curly brace.
I'm not trying to embed variable template tags within block template tags. All I want to do is something like this:
{% templatetag openbrace %}{{ somevariable }}
because I can't find any other way to put a brace in front of a variable template tag.
Sorry for my overbearing persistence, but this just seems way to complicated for what should be a really simple thing. If I'm doing a string in python, and I want to put in a quotation mark somewhere, all I have to do is put a backslash in front of my quotation mark, and everything's happy. I don't have to rewrite the parser or anything.
comment:5 by , 19 years ago
OHHHHH, *now* I see what you want to do! Yeah, I completely misunderstood -- my apologies. That sounds like a good addition to the default template tag library. Whew!
comment:7 by , 19 years ago
I've attached patches which implement two extra constants for the template system to add a "single" variation of the variable start/end tags, and allows the templatetag
tag to output them.
comment:8 by , 19 years ago
Summary: | templatetag should do openbrace, closebrace → [patch] templatetag should do openbrace, closebrace |
---|
(also, as to whether this should go in, I'm pretty much neutral; if the template system does indeed choke on a single brace before a variable, then this is necessary, but I've not verified that)
comment:9 by , 19 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
To accomplish your example, just write a template tag with this syntax:
{% includegraphics filename %}
Example:
{% includegraphics 'somefile.jpg' %}