#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)
Changed 10 years ago by
Attachment: | noparse.py added |
---|
comment:1 Changed 10 years ago by
Cc: | dgouldin@… added |
---|---|
Needs documentation: | set |
Needs tests: | set |
comment:2 Changed 10 years ago by
Patch needs improvement: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:3 Changed 10 years ago by
Owner: | changed from nobody to Jeremy Dunck |
---|---|
Status: | new → assigned |
comment:4 Changed 10 years ago by
Owner: | changed from Jeremy Dunck to nobody |
---|---|
Status: | assigned → new |
comment:5 Changed 10 years ago by
Has patch: | set |
---|
comment:6 Changed 10 years ago by
Cc: | jdunck@… added |
---|
comment:7 Changed 10 years ago by
comment:8 Changed 10 years ago by
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 Changed 10 years ago by
Cc: | davidnovakovic@… added |
---|
comment:10 Changed 10 years ago by
Severity: | → Normal |
---|---|
Type: | → New feature |
comment:11 Changed 10 years ago by
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 Changed 9 years ago by
Cc: | kmike84@… added |
---|
comment:13 Changed 9 years ago by
Needs documentation: | unset |
---|---|
Needs tests: | unset |
Patch needs improvement: | unset |
Triage Stage: | Accepted → Ready for checkin |
Version: | 1.2 |
comment:14 Changed 9 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:15 Changed 9 years ago by
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 Changed 9 years ago by
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Triage Stage: | Ready for checkin → Design decision needed |
comment:17 Changed 9 years ago by
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 Changed 9 years ago by
Owner: | changed from nobody to Aymeric Augustin |
---|---|
Status: | reopened → new |
Assigning to myself so I don't forget to resolve this, one way or another.
comment:19 Changed 9 years ago by
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.
Changed 9 years ago by
Attachment: | 14502-no-customizable-end-tag.patch added |
---|
comment:20 Changed 9 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:21 Changed 9 years ago by
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?