Improve nested extends (super.super) example.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by jab · committed by jab · parent b5c6c9c · Browse files · 1 file·+24 added−19 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+24 added−19 removed
- other:+24 added−19 removed
Provenance
- Commit
72e5573- Tree
32ff0a7- Author
jab <jab@users.noreply.github.com>- Committer
jab <jab@users.noreply.github.com>- Parent
b5c6c9c
1 file changed+24 added−19 removed
modified:docs/templates.rst+24 added-19 removed
423 unmodified lines424 425 Super Blocks426 ~~~~~~~~~~~~427 428-It's possible to render the contents of the parent block by calling `super`.428+It's possible to render the contents of the parent block by calling ``super()``.429 This gives back the results of the parent block::430 431 {% block sidebar %}432 <h3>Table Of Contents</h3>1 unmodified line434 {{ super() }}435 {% endblock %}436 437 438-Nesting template extends.439-~~~~~~~~~~~~~~~~~~~~~~~~~438+Nesting extends439+~~~~~~~~~~~~~~~440 441-In the case of multiple levels of %extends, the childmost {% block %} substitutes into the parent template. For instance,441+In the case of multiple levels of ``{% extends %}``,442+``super`` references may be chained (as in ``super.super()``)443+to skip levels in the inheritance tree.444 443-::445+For example::446 445- #a1.tmpl446- From A1: {% block body %} Want-this-to-be-included. {% endblock %}447+ # parent.tmpl448+ body: {% block body %}Hi from parent.{% endblock %}449 448- #a2.tmpl449- {% extends "a1.tmpl" %}450- {% block body %} Want-this-to-be-skipped. {{super()}} {% endblock %}450+ # child.tmpl451+ {% extends "parent.tmpl" %}452+ {% block body %}Hi from child. {{ super() }}{% endblock %}453 452- #a3.tmpl453- {% extends "a2.tmpl" %}454- {% block body %} Some text {% endblock %}454+ # grandchild1.tmpl455+ {% extends "child.tmpl" %}456+ {% block body %}Hi from grandchild1.{% endblock %}457 456- #a4.tmpl457- {% extends "a2.tmpl" %}458- {% block body %} From A4: {{super.super()}} {% endblock %}458+ # grandchild2.tmpl459+ {% extends "child.tmpl" %}460+ {% block body %}Hi from grandchild2. {{ super.super() }} {% endblock %}461 462 461-Rendering `a2.tmpl` will output `From A1: Want-this-to-be-skipped`. The text `Want-this-to-be-included.` is rendered because the `super()` call render as the text from the parent template into the block, which will then be substitute into topmost template.463+Rendering ``child.tmpl`` will give464+``body: Hi from child. Hi from parent.``465 463-Rendering `a3.tmpl` will output `From A1: Some Text`. We substitute the block text into the parent template.466+Rendering ``grandchild1.tmpl`` will give467+``body: Hi from grandchild1.``468 465-Rendering `a4.tmpl` will output `From A1: From A4: Want-this-to-be-included.` Here, we are accessing the `super` property from the `super` object to get access to the text in grandparent's block. Had we just done `super()`, this would have returned `From A1: From A4: Want-this-to-be-skipped. Want-this-to-be-included.`.469+Rendering ``grandchild2.tmpl`` will give470+``body: Hi from grandchild2. Hi from parent.``471 472 473 Named Block End-Tags474 ~~~~~~~~~~~~~~~~~~~~1262 unmodified lines