Skip to content
Myr

Merge pull request #1015 from jab/pr-1011

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Document nested extends and super.super().

authored by Joshua Bronson · committed by GitHub · parents a486b37, a811d86 · Browse files · 2 files+37 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+37 added−1 removed

  • other:+37 added−1 removed

2 files+37 added−1 removed

modified:docs/api.rst+1 added
1API2===34.. module:: jinja25 :noindex:6 :synopsis: public Jinja2 API78This document describes the API to Jinja2 and not the template language. It9will be most useful as reference to those implementing the template interface
926 unmodified lines
modified:docs/templates.rst+36 added-1 removed
423 unmodified lines
424425Super Blocks426~~~~~~~~~~~~427428It's possible to render the contents of the parent block by calling `super`.428It's possible to render the contents of the parent block by calling ``super()``.429This gives back the results of the parent block::430431 {% block sidebar %}432 <h3>Table Of Contents</h3>
1 unmodified line
434 {{ super() }}435 {% endblock %}436437438Nesting extends439~~~~~~~~~~~~~~~440441In the case of multiple levels of ``{% extends %}``,442``super`` references may be chained (as in ``super.super()``)443to skip levels in the inheritance tree.444445For example::446447 # parent.tmpl448 body: {% block body %}Hi from parent.{% endblock %}449450 # child.tmpl451 {% extends "parent.tmpl" %}452 {% block body %}Hi from child. {{ super() }}{% endblock %}453454 # grandchild1.tmpl455 {% extends "child.tmpl" %}456 {% block body %}Hi from grandchild1.{% endblock %}457458 # grandchild2.tmpl459 {% extends "child.tmpl" %}460 {% block body %}Hi from grandchild2. {{ super.super() }} {% endblock %}461462463Rendering ``child.tmpl`` will give464``body: Hi from child. Hi from parent.``465466Rendering ``grandchild1.tmpl`` will give467``body: Hi from grandchild1.``468469Rendering ``grandchild2.tmpl`` will give470``body: Hi from grandchild2. Hi from parent.``471472473Named Block End-Tags474~~~~~~~~~~~~~~~~~~~~475476Jinja2 allows you to put the name of the block after the end tag for better
1260 unmodified lines