Opened 15 years ago

Closed 15 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: no UI/UX: no

Description

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:

base.html:

<head>
{% include "table-include" "jscript" %}
</head> 
<body>
<table>
{% include "table-include" "header" %}
{% for row in rows %}
 {% include "table-include" "rowdata" %}
{% endfor %}
</table>
</body>

table-include.html:

{% block jscript %}
<script> <!- --> </script>
{% endblock %}
{% block header %}
<tr><th>heading</th></tr>
{% endblock %}
{% block rowdata %}
<tr><td>{{row.data}}</td></tr>
{% 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 15 years ago.

Download all attachments as: .zip

Change History (2)

by Marco Paolini, 15 years ago

Attachment: 11832.0.patch added

comment:1 by Chris Beaven, 15 years ago

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