Opened 14 years ago

Closed 14 years ago

Last modified 12 years ago

#2778 closed enhancement (wontfix)

[patch] includeblock tag

Reported by: Chris Beaven Owned by: Adrian Holovaty
Component: Template system Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Similar to {% include %} but rather than rendering the entire template, this renders a specific block of the given template with the current context.

Both the template name and the block name can either be variables or hard-coded (quoted) strings.

The following example includes the "navigation" block of the template "main.htm":

{% includeblock "main.htm" "navigation" %}

Attachments (1)

includeblock.patch (5.6 KB) - added by Chris Beaven 14 years ago.
patch including tests and documentation

Download all attachments as: .zip

Change History (5)

Changed 14 years ago by Chris Beaven

Attachment: includeblock.patch added

patch including tests and documentation

comment:1 Changed 14 years ago by Adrian Holovaty

Resolution: wontfix
Status: newclosed

Not "core" enough for Django proper, and it's yet another way of including things -- we've already got ssi, include and blocks -- but please do post this to the user-contributed template tags/filters part of the Django wiki.

comment:2 Changed 12 years ago by Antonis Christofides

Note that the patch included appears to be too slow. This is probably because it needs to load/compile the entire included template each time a block is needed, so if, for example, you have

{% includeblock "main.htm" "block1" %}
{% includeblock "main.htm" "block2" %}
{% includeblock "main.htm" "block3" %}

then it appears to be loading and compiling main.htm three times. You can be orders of magnitude faster if, instead, you break main.htm into smaller files and simply {% include %} the smaller files whenever you need them.

comment:3 Changed 12 years ago by Chris Beaven

I'm apathetic about the patch now, anyway. But the load-compile slowness is a generic problem which I addressed in a more recent ticket by caching templates.

comment:4 Changed 12 years ago by Johannes Dollinger

I have a patch(1) that introduces a template cache in Context and would make something like the following trivial to implement:

{% sub "block1" %}
{% endsub %}

{% include "block1" %}

Would that fit the orginal use-case?


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