Opened 3 years ago

Last modified 11 months ago

#23356 new Cleanup/optimization

Unable to create template tag which behaves similar to {% verbatim %}

Reported by: Jacob Rief Owned by: nobody
Component: Template system Version: master
Severity: Normal Keywords: verbatim
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by shayneoneill)

Currently it is impossible to create custom template tags which behave similar to {% verbatim %} .
The reason is in Lexer.create_token(). There, the class member self.verbatim is set for template blocks in "verbatim" state. It is impossible to turn on that state from outside, ie. a template tag.

Fixing this, would be as simple as changing if block_content[:9] in ('verbatim', 'verbatim ') to if block_content.startswith('verbatim') or to if block_content[:9] in ('verbatim', 'verbatim ', 'verbatim_').
Then all template tags beginning with verbatim..., would start in "verbatim" state. I don't assume this will break any existing code; who starts the name of a templatetag with 'verbatim...' if not for that purpose?

Background information why this is useful:
Templates syntax for Django and AngularJS is very similar, and with some caveats it is possible to reuse a Django template for rendering in AngularJS. I therefore attempted to add a context sensitive variation of the verbatim tag to this app https://github.com/jrief/django-angular, but was hindered by this issue.

BTW: This part of the Django code did not change from 1.6 up to master.

Change History (6)

comment:2 Changed 3 years ago by shayneoneill

Description: modified (diff)

comment:3 Changed 3 years ago by shayneoneill

Description: modified (diff)

comment:5 Changed 19 months ago by None

I am creating template tag and need get code between {% mytag %}...{% endmytag %}.
I read code and saw that similar template tag "verbatim" is hardcode using in Lexer.
This is bad idea because nobody can't create template like "verbatim".
Please, improve this thing and make django template system more convenient and flexible.

comment:6 Changed 19 months ago by None

Has patch: unset
Type: UncategorizedCleanup/optimization

comment:7 Changed 19 months ago by Jacob Rief

BTW: In the meantime I found another solution for the described problem.

comment:8 Changed 19 months ago by Tim Graham

Triage Stage: UnreviewedAccepted

I'm open to a solution, although I'm not sure if the change proposed in the description is ideal.

Note: See TracTickets for help on using tickets.
Back to Top