Code

Opened 5 years ago

Closed 5 years ago

#11832 closed (wontfix)

include tag with optional block argument (selective include feature)

Reported by: mpaolini 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:

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 mpaolini 5 years ago.

Download all attachments as: .zip

Change History (2)

Changed 5 years ago by mpaolini

comment:1 Changed 5 years ago by SmileyChris

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to wontfix
  • Status changed from new to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.