Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to complement the block of parent template?

I have first.html:

    {% block title %}
        hi there
    {% endblock %}

    {% block content %}
        blah-blah
    {% endblock %}

    {% block footer %}
        bye
    {% endblock %}

and second.html. How can I incude all first.html page to second.html and complement content block like this:

hi there
blah-blah
this text is from second.html
bye

I've tryed

{% extends "first.html" %}
this text is from second.html

(just nothing added) and

{% extends "first.html" %}
{% block content %}
    this text is from second.html
{% endblock %}

(block content is overrided).

like image 265
Pavel Antspovich Avatar asked Jan 19 '26 03:01

Pavel Antspovich


1 Answers

You can make use of {{ block.super }} [Django-doc] here when you want to render the original content as well. For example:

{% extends 'first.html' %}
{% block content %}
    {{ block.super }}
    this text is from second.html
{% endblock %}
like image 141
Willem Van Onsem Avatar answered Jan 22 '26 09:01

Willem Van Onsem



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!