#16318 closed New feature (duplicate)
Add a standard verbatim tag
| Reported by: | Calvin Spealman | Owned by: | nobody |
|---|---|---|---|
| Component: | Template system | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
jQuery templates use constructs like:
{{if condition}} print something{{/if}}
This, of course, completely screws up Django templates,
because Django thinks {{ and }} mean something.
Wrap {% verbatim %} and {% endverbatim %} around those
blocks of jQuery templates and this will try its best
to output the contents with no changes.
from django import template
register = template.Library()
class VerbatimNode(template.Node):
def __init__(self, text):
self.text = text
def render(self, context):
return self.text
@register.tag
def verbatim(parser, token):
text = []
while 1:
token = parser.tokens.pop(0)
if token.contents == 'endverbatim':
break
if token.token_type == template.TOKEN_VAR:
text.append('{{')
elif token.token_type == template.TOKEN_BLOCK:
text.append('{%')
text.append(token.contents)
if token.token_type == template.TOKEN_VAR:
text.append('}}')
elif token.token_type == template.TOKEN_BLOCK:
text.append('%}')
return VerbatimNode(''.join(text))
Change History (3)
comment:1 by , 14 years ago
comment:2 by , 14 years ago
| Resolution: | → duplicate |
|---|---|
| Status: | new → closed |
Related discussion threads:
- http://groups.google.com/group/django-developers/browse_thread/thread/e914638d8fe859de/752e44fd9ddc8229?lnk=gst&q=verbatim#752e44fd9ddc8229
- http://groups.google.com/group/django-developers/browse_thread/thread/eda0e9187adcbe36/4a27e9a79266cf55?lnk=gst&q=verbatim#4a27e9a79266cf55
This is actually a duplicate of #14502 which is mentioned in the first of these two threads.
Note:
See TracTickets
for help on using tickets.
(taken from https://gist.github.com/629508 )