Up to this point, we've been filling blocks with content from child templates. What if you wanted to leave any default content in that block and add to it the contents of the child template?
To do this, we use a special variable called {{
block.super
}}
. This variable holds whatever the block contains before being overwritten by the block from a child template.
In our mycompany/templates/site_base.html
file, let's add a default page title:
<title>{% block title %}MyCompany{% endblock title %}</title>
We want to leave the word "MyCompany
" in the title of the page and append more text to it, and so we use the {{
block.super
}}
variable in our child template.
Edit the contents of the title
block in the mycompany/templates/press/detail.html
file:
{% block title %} {{ block.super }}: {{ press.title }} {% endblock title %}
When the page is rendered, the page title will be output with "MyCompany
:" in front of the page title.