update docs about required blocks (#1340)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by GitHub · parent b5a00c8 · Browse files · 2 files·+27 added−21 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+27 added−21 removed
- other:+27 added−21 removed
Provenance
- Commit
c3b34a0- Tree
18f91d9- Author
David Lord <davidism@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
b5a00c8
2 files changed+27 added−21 removed
modified:docs/templates.rst+23 added-18 removed
539 unmodified lines540 When overriding a block, the `scoped` modifier does not have to be provided.541 542 543 Required Blocks544-~~~~~~~~~~~~~~~~~~~~~~~544+~~~~~~~~~~~~~~~545 546-Blocks can be marked as required. They must be overridden at some point,547-but not necessarily by the direct child template. Required blocks can548-only contain whitespace or comments, and they cannot be rendered directly.546+Blocks can be marked as ``required``. They must be overridden at some547+point, but not necessarily by the direct child template. Required blocks548+may only contain space and comments, and they cannot be rendered549+directly.550 550-For example::551+.. code-block:: jinja552+ :caption: ``page.txt``553 552- # parent.tmpl553- body: {% block body required %}{% endblock %}554+ {% block body required %}{% endblock %}555 555- # child.tmpl556- {% extends "parent.tmpl" %}556+.. code-block:: jinja557+ :caption: ``issue.txt``558 558- # grandchild.tmpl559- {% extends "child.tmpl" %}559+ {% extends "page.txt" %}560- {% block body %}Hi from grandchild.{% endblock %}560 561+.. code-block:: jinja562+ :caption: ``bug_report.txt``563 563-Rendering ``child.tmpl`` will give564-``TemplateRuntimeError``564+ {% extends "issue.txt" %}565+ {% block body %}Provide steps to demonstrate the bug.{% endblock %}566 566-Rendering ``grandchild.tmpl`` will give567-``Hi from grandchild.``567+Rendering ``page.txt`` or ``issue.txt`` will raise568+``TemplateRuntimeError`` because they don't override the ``body`` block.569+Rendering ``bug_report.txt`` will succeed because it does override the570+block.571 569-When combined with ``scoped``, the ``required`` modifier must be placed `after`570-the scoped modifier. Here are some valid examples::572+When combined with ``scoped``, the ``required`` modifier must be placed573+*after* the scoped modifier. Here are some valid examples:574 575+.. code-block:: jinja576+577 {% block body scoped %}{% endblock %}578 {% block body required %}{% endblock %}579 {% block body scoped required %}{% endblock %}580 1287 unmodified linesmodified:CHANGES.rst+4 added-3 removed
17 unmodified lines18 constant input. :issue:`1279`19 - Fix UndefinedError incorrectly being thrown on an undefined variable20 instead of ``Undefined`` being returned on21 ``NativeEnvironment`` on Python 3.10. :issue:`1335`22-- Add ``required`` attribute to blocks that must be overridden at some23- point, but not necessarily by the direct child :issue:`1147`24-- Deprecate ``autoescape`` and ``with`` extensions :issue:`1203`22+- Blocks can be marked as ``required``. They must be overridden at23+ some point, but not necessarily by the direct child. :issue:`1147`24+- Deprecate the ``autoescape`` and ``with`` extensions, they are25+ built-in to the compiler. :issue:`1203`26 27 28 Version 2.11.229 --------------770 unmodified lines