askama
askama copied to clipboard
[QUESTION] Confusion about template inheritence
In the book, the following base template is used:
<!DOCTYPE html>
<html lang="en">
<head>
<title>{% block title %}{{ title }} - My Site{% endblock %}</title>
{% block head %}{% endblock %}
</head>
<body>
<div id="content">
{% block content %}{% endblock %}
</div>
</body>
</html>
What does it mean to have the {{ title }} tag inside of the block? When I override the title using
{% block title %}Homepage{% endblock %}
The entirety of the block is replaced and the following is the result:
<title>Homepage</title>
so I can't see what the {{ title }} changes.
You don't have to override the title block. Then "{{ title }} - My Site" is used as a fallback / default.
What is {{ title }} replaced with in that case?
The child template overrides:
{% block title %}{{ title }} - My Site{% endblock %}
With:
{% block title %}Homepage{% endblock %}
As your new title block, doesn't contain {{ title }}, then there's nothing to be replaced
Ohhhh so to be clear here, if the child template doesn't override title, then title must be defined in the Template struct.
Otherwise, it is replaced what it is overriding it with?
That's right.
If you can suggest some text for the book that would have clarified this for you, that would be great. Bonus points if you do it as a PR!