Skip to content

Instantly share code, notes, and snippets.

@issackelly
Created April 19, 2011 16:48
Show Gist options
  • Select an option

  • Save issackelly/928783 to your computer and use it in GitHub Desktop.

Select an option

Save issackelly/928783 to your computer and use it in GitHub Desktop.
Django Template {{ block.super }} example
# Template: A.html
<html>
<head></head>
<body>
{% block hello %}
HELLO
{% endblock %}
</body>
</html>
# Template B.html
{% extends "A.html" %}
{% block hello %}
World
{% endblock %}
# Rendered Template B
<html>
<head></head>
<body>
World
</body>
</html>
# Template C
{% extends "A.html" %}
{% block hello %}
{{ block.super }} World
{% endblock %}
# Rendered Template C
<html>
<head></head>
<body>
Hello World
</body>
</html>
@rahulkp220

Copy link
Copy Markdown

Thanks. Helped me to understand it more clearly :-)

@alonek1

alonek1 commented Jun 20, 2016

Copy link
Copy Markdown

thanks

@toti1212

Copy link
Copy Markdown

👍 Nice!

@laoyur

laoyur commented Aug 21, 2016

Copy link
Copy Markdown

nice example !

@Jaskaran-smtc

Copy link
Copy Markdown

thanks for explaining this clearly

@juliotoscano

Copy link
Copy Markdown

Thanks so much!

@emm7494

emm7494 commented Jan 11, 2017

Copy link
Copy Markdown

Very helpful

@emacstheviking

Copy link
Copy Markdown

Surely that's wrong??? Template C should inherit from template B other it won't work will it?

@Ausqa21

Ausqa21 commented Jan 27, 2017

Copy link
Copy Markdown

Thanks a lot for the explanation

@nagracks

nagracks commented Mar 2, 2017

Copy link
Copy Markdown

Thanx

@onitonitonito

Copy link
Copy Markdown

very helpful! Thanx

@diek

diek commented Sep 22, 2017

Copy link
Copy Markdown

Nice example, I created a simple working version. https://github.com/diek/superduper

@artu-hnrq

Copy link
Copy Markdown

Thanks. Helped me to understand it more clearly :-)

Yeah!

@scotth527

Copy link
Copy Markdown

On line 36 why is it not HELLO World? If in the parent template the HELLO is in all caps?

@artu-hnrq

artu-hnrq commented Apr 16, 2021

Copy link
Copy Markdown

On line 36 why is it not HELLO World? If in the parent template the HELLO is in all caps?

You are right, @scotth527!
{{ block.super }} will render the same content present in the current block of extended template.
Thus, in this case, HELLO World

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment