#23356: Unable to create template tag which behaves similar to {% verbatim %}
---------------------------------+--------------------------------------
     Reporter:  jrief            |                    Owner:  nobody
         Type:  Uncategorized    |                   Status:  closed
    Component:  Template system  |                  Version:  master
     Severity:  Normal           |               Resolution:  wontfix
     Keywords:  verbatim         |             Triage Stage:  Unreviewed
    Has patch:  1                |      Needs documentation:  0
  Needs tests:  0                |  Patch needs improvement:  0
Easy pickings:  0                |                    UI/UX:  0
---------------------------------+--------------------------------------
Description changed by shayneoneill:

Old description:

> 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.
>
> For the purposes of anyone coming across this ticket and pulling their
> hair out over it, heres a template tag that might ease the pain;-
> {{{
>
> from django import template
>
> register = template.Library()
>
> @register.filter(name='specialbracket')
> def specialbracket(value):
>     if value == 'left':
>         return "{{"
>     elif value == 'right':
>         return "}}"
>     else:
>         return "??"
> }}}
>
> And the above example solved with this tag;-
>
> {{{
>         <td class="field-{{ident}}">{{ 'left'|specialbracket }}
> computer.{{field}} {{ 'right'|specialbracket }} </td>
>
> }}}

New description:

 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.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/23356#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/063.4281575daa1be32cdd5f6dc4d3ede305%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to