#36130: Add inclusion support for simple block tags
-----------------------------+-------------------------------------------
Reporter: Jake Howard | Type: New feature
Status: new | Component: Template system
Version: | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+-------------------------------------------
Django's template system allows creating tags which include other
templates:
{{{#!python
@register.inclusion_tag("results.html")
def show_results(poll):
choices = poll.choice_set.all()
return {"choices": choices}
}}}
However, with the addition of `simple_block_tag` in #35535, it would be
nice to combine the 2 into a `inclusion_block_tag`. This creates a form of
reusable component for Django template, combining context transformation,
rendering and internal content. There are a number of libraries in the
Django ecosystem which achieve this (eg `slippers`), so there's clearly an
appetite for this functionality.
{{{#!python
@register.inclusion_block_tag("results.html")
def show_results(content, poll):
choices = poll.choice_set.all()
return {"content": content, "choices": choices}
}}}
{{{#!django
{% show_results poll %}
This content gets captured too
{% endmysimpletag %}
}}}
The API matches the existing `inclusion_tag`, but with an additional
required `content` argument containing the (rendered) template content.
--
Ticket URL: <https://code.djangoproject.com/ticket/36130>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/0107019494351f6e-25969a05-6553-401f-806d-e6901b7fa101-000000%40eu-central-1.amazonses.com.