﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
30539	Django - “with / as” to fill block is not working.	Jay Day	nobody	"
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)
"	Bug	closed	Template system	dev	Normal	worksforme	templates, blocks, with		Unreviewed	0	0	0	0	0	0
