mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Fixed #36410 -- Added support for Template Partials to the Django Template Language.
Introduced `{% partialdef %}` and `{% partial %}` template tags to
define and render reusable named fragments within a template file.
Partials can also be accessed using the `template_name#partial_name`
syntax via `get_template()`, `render()`, `{% include %}`, and other
template-loading tools.
Adjusted `get_template()` behavior to support partial resolution, with
appropriate error handling for invalid names and edge cases. Introduced
`PartialTemplate` to encapsulate partial rendering behavior.
Includes tests and internal refactors to support partial context
binding, exception reporting, and tag validation.
Co-authored-by: Carlton Gibson <carlton@noumenal.es>
Co-authored-by: Natalia <124304+nessita@users.noreply.github.com>
Co-authored-by: Nick Pope <nick@nickpope.me.uk>
This commit is contained in:
2
tests/template_tests/templates/partial_base.html
Normal file
2
tests/template_tests/templates/partial_base.html
Normal file
@@ -0,0 +1,2 @@
|
||||
{% block main %}
|
||||
{% endblock main %}
|
||||
9
tests/template_tests/templates/partial_child.html
Normal file
9
tests/template_tests/templates/partial_child.html
Normal file
@@ -0,0 +1,9 @@
|
||||
{% extends 'partial_base.html' %}
|
||||
|
||||
{% partialdef extra-content %}
|
||||
Extra Content
|
||||
{% endpartialdef %}
|
||||
|
||||
{% block main %}
|
||||
Main Content
|
||||
{% endblock %}
|
||||
15
tests/template_tests/templates/partial_examples.html
Normal file
15
tests/template_tests/templates/partial_examples.html
Normal file
@@ -0,0 +1,15 @@
|
||||
{% partialdef test-partial %}
|
||||
TEST-PARTIAL-CONTENT
|
||||
{% endpartialdef %}
|
||||
|
||||
{% block main %}
|
||||
BEGINNING
|
||||
{% partial test-partial %}
|
||||
MIDDLE
|
||||
{% partial test-partial %}
|
||||
END
|
||||
{% endblock main %}
|
||||
|
||||
{% partialdef inline-partial inline %}
|
||||
INLINE-CONTENT
|
||||
{% endpartialdef %}
|
||||
Reference in New Issue
Block a user