#14502 closed New feature (fixed)
Feature: escape hatch for colliding template syntax in Django templates
Reported by: | David Gouldin | Owned by: | Aymeric Augustin |
---|---|---|---|
Component: | Template system | Version: | |
Severity: | Normal | Keywords: | |
Cc: | dgouldin@…, jdunck@…, davidnovakovic@…, kmike84@… | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
As discussed in django-developers:
http://groups.google.com/group/django-developers/browse_thread/thread/e914638d8fe859de
There is a need for a template block tag which renders template syntax characters within the block as normal text. This serves as an escape hatch to avoid syntax collisions when using a template language meant to be rendered on the client, not the server. A potential implementation is attached.
Attachments (2)
Change History (24)
by , 14 years ago
Attachment: | noparse.py added |
---|
comment:1 by , 14 years ago
Cc: | added |
---|---|
Needs documentation: | set |
Needs tests: | set |
comment:2 by , 14 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 14 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 14 years ago
Owner: | changed from | to
---|---|
Status: | assigned → new |
comment:5 by , 14 years ago
Has patch: | set |
---|
comment:6 by , 14 years ago
Cc: | added |
---|
comment:7 by , 14 years ago
comment:8 by , 14 years ago
Eric, to be clear, are you referring to Lexer.create_token using .strip?
If so, I see the need for that (later context[var_name] kinds of lookups), but perhaps tokens could hang on to their raw contents? Or perhaps a final step in Parser could perform those strips after nodes have been constructed? (Neither sounds ideal...)
comment:9 by , 14 years ago
Cc: | added |
---|
comment:10 by , 13 years ago
Severity: | → Normal |
---|---|
Type: | → New feature |
comment:11 by , 13 years ago
Easy pickings: | unset |
---|---|
UI/UX: | unset |
#16318 was a duplicate. It contains an alternative implementation.
Another discussion : http://groups.google.com/group/django-developers/browse_thread/thread/eda0e9187adcbe36
"verbatim" is a better name than "noparse" IMO — that's how people call this feature spontaneously.
comment:12 by , 13 years ago
Cc: | added |
---|
comment:13 by , 13 years ago
Needs documentation: | unset |
---|---|
Needs tests: | unset |
Patch needs improvement: | unset |
Triage Stage: | Accepted → Ready for checkin |
Version: | 1.2 |
comment:14 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:15 by , 12 years ago
I'm not sure I understand the purpose of the alternate closing tag, can you elaborate (in the docs and here) why this was needed to be added (as it's a rather extensive departure of a core tag)?
comment:16 by , 12 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Triage Stage: | Ready for checkin → Design decision needed |
comment:17 by , 12 years ago
Has patch: | unset |
---|
So, I just reviewed the mailing list discussions on this topic.
Clearly there's some demand for a verbatim
tag, and it should be implemented in the template engine itself (because the verbatim content shouldn't be parsed).
Personally, I'd prefer if the verbatim text could contain any text -- including {% endverbatim %}
-- otherwise someone's going to notice and complain. But we could very well live without this possibility: there's always the (ugly) alternative of splitting the {% endverbatim %}
to output, like this:
{% verbatim %}bla bla {% end{% endverbatim %}{% verbatim %}verbatim %} bla bla{% endverbatim %}
For the record, the alternate closing tag was suggested on the mailing list (and also in a few follow up posts). Chris implemented it and considered his patch ready to go, basically endorsing the idea. The implementation looked reasonable to me, so I went ahead and committed the patch.
comment:18 by , 12 years ago
Owner: | changed from | to
---|---|
Status: | reopened → new |
Assigning to myself so I don't forget to resolve this, one way or another.
comment:19 by , 12 years ago
Triage Stage: | Design decision needed → Accepted |
---|
Following a discussion with Jannis, here's a patch that removes the overridable end tag. It's trading debatable benefits for some complexity and doesn't fit so well with the rest of the template language. Specifically, it could make refactoring the template language significantly harder.
If we absolutely wanted to keep a way to escape {% endverbatim %}
, I'd suggest using {% verbatim blahblah %}...{% endverbatim blahblah %}
, similar to what the {% block %}
tag does.
by , 12 years ago
Attachment: | 14502-no-customizable-end-tag.patch added |
---|
comment:20 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:21 by , 12 years ago
Jannis: if you're still not happy with how this looks, then I'm fine with just removing this "edge case" and never allowing for having {% endverbatim %}
unrendered.
I don't think this patch is quite sufficient because it can actually change the contents of the text in the noparse block. Specifically, it won't preserve whitespace within things that it interprets as blocks or variables.
However, I don't think it's going to be possible to escape out of parsing using the usual templatetag constructs, because it's already tokenized and parsed by the time it's handed off to the node.
Maybe a pre-processing step that happens before everything else is in order?