Code

Opened 8 years ago

Closed 8 years ago

Last modified 6 years ago

#2778 closed enhancement (wontfix)

[patch] includeblock tag

Reported by: SmileyChris Owned by: adrian
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: UI/UX:

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)

includeblock.patch (5.6 KB) - added by SmileyChris 8 years ago.
patch including tests and documentation

Download all attachments as: .zip

Change History (5)

Changed 8 years ago by SmileyChris

patch including tests and documentation

comment:1 Changed 8 years ago by adrian

  • Resolution set to wontfix
  • Status changed from new to 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 Changed 6 years ago by aptiko

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 6 years ago by SmileyChris

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 6 years ago by emulbreh

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?

(1) http://einfallsreich.net/projekte/thenewstuff/django/

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.