#30539: Django - “with / as” to fill block is not working
-------------------------------------+-------------------------------------
               Reporter:  Jay-Dai    |          Owner:  nobody
                   Type:  Bug        |         Status:  new
              Component:  Template   |        Version:  2.2
  system                             |       Keywords:  templates, blocks,
               Severity:  Normal     |  with
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  1          |
-------------------------------------+-------------------------------------
 I am trying to not repeat myself in Django, but use the same content for 2
 blocks. The content is static so I would rather have in in my templates
 than sending them through views.

 This was the solution I found :


 {{{
      {% with "My title" as title %}
          {% block TitleOne %}{{ title }}{% endblock TitleOne %}
          {% block TitleTwo %}{{ title }}{% endblock TitleTwo %}
 {% endwith %}
 }}}


 In a templates that extends a second one that uses the blocks TitleOne and
 TitleTwo .

 But it does not work. If I write it like :


 {{{
 {% block TitleOne %}"My title"{% endblock TitleOne %}
 {% block TitleTwo %}"My title"{% endblock TitleTwo %}
 }}}


 It works perfectly. But of course it s not DRY. If I write it like :


 {{{
      {% with "My title" as title %}
          {% block TitleOne %}"My title"{% endblock TitleOne %}
          {% block TitleTwo %}{{ title }}{% endblock TitleTwo %}
 {% endwith %}
 }}}


 Only the 1st one displays right. But not DRY as well.

 Tried another way suggested in Django's docs :
 https://docs.djangoproject.com/en/2.2/ref/templates/builtins/#with

 {{{
 {% with title="My title" %}
              {% block TitleOne %}"My title"{% endblock TitleOne %}
              {% block TitleTwo %}{{ title }}{% endblock TitleTwo %}
     {% endwith %}
 }}}

 Only the 1st one displayed too..

 (I am using Django 2.2.1, Python 3.7.3)

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30539>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.15da27084d9af8ad8b603ac49228330e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to