#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 |
Description
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)
Change History (5)
by , 18 years ago
Attachment: | includeblock.patch added |
---|
comment:1 by , 18 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
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 by , 16 years ago
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 by , 16 years ago
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 by , 16 years ago
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?
patch including tests and documentation