Opened 9 years ago

Closed 9 years ago

#11832 closed (wontfix)

include tag with optional block argument (selective include feature)

Reported by: Marco Paolini Owned by: nobody
Component: Template system Version: 1.1
Severity: Keywords: feature
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


Sometimes, for clarity, an included template contains code for different parts of the parent.

This patch allows an extra block optional argument to the include tag. If specified, only that particular block of the included template will be included.

an example:


{% include "table-include" "jscript" %}
{% include "table-include" "header" %}
{% for row in rows %}
 {% include "table-include" "rowdata" %}
{% endfor %}


{% block jscript %}
<script> <!- --> </script>
{% endblock %}
{% block header %}
{% endblock %}
{% block rowdata %}
{% endblock %}

Without this patch you would need three different included tepmlates like: table-include-js.html, table-include-header.html and table-include-rowdata.html making the whole thing less maintainable

if the block in arg is not found maybe we should raise a TemplateSyntaxError (or maybe not)

patch is just a proof of concept. Tests included

comments welcome

Attachments (1)

11832.0.patch (5.0 KB) - added by Marco Paolini 9 years ago.

Download all attachments as: .zip

Change History (2)

Changed 9 years ago by Marco Paolini

Attachment: 11832.0.patch added

comment:1 Changed 9 years ago by Chris Beaven

Resolution: wontfix
Status: newclosed

This was declined way back in #2778. Bring it up on django-dev google group if you want to suggest the issue should be reviewed again.

Note: See TracTickets for help on using tickets.
Back to Top