2

For example I have top.html which will be included from within base.html. How to override contents of top.html after including?

1 Answer 1

2

You didn't understand templates idealogy.
Right way is create base.html like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Some app - {% block header %}{% endblock %}</title>
    </head>
    <body>
        <h1>{% block title %}Default title{% endblock %}</h1>
        {% block content %}{% endblock %}
    </body>
</html>

And then in page.html you can override header for example:

{% extends "base.html" %}
{% block title %}Some page{% endblock %}
{% block header %}Overriden header{% endblock %}
{% block content %}
    Some content
{% endblock %}
Sign up to request clarification or add additional context in comments.

1 Comment

I figured it out, thanks @Stanislav Feldman though the examples do not satisfy my requirements)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.