Opened 18 years ago

Closed 18 years ago

#3171 closed enhancement (invalid)

[patch] Support for dynamic values in inclusion_tag template name

Reported by: nick@… Owned by: Adrian Holovaty
Component: Template system Version: dev
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

The inclusion_tag doesn't support dynamic values in the template name, which I found I needed in several places when creating custom template tags. Initially I just wrote my own helper function but it was so similar to inclusion_tag I thought I would post a patch here in case it was useful.

A simple example of how I'm using this for a generic "filtered" list (similar to the admin ChangeList) with different templates for different lists:

def filters(fl):
    return {'fl': fl}
filters = register.inclusion_tag('%s/filters.html', inclusion_params=('fl.template_path',))(filters)

Each item in inclusion_params is resolved and then all are passed as a tuple into the template_name string to generate the final template filename. Note that the "fl" item in inclusion_params variable refers to the "fl" parameter to the filters function, not to some arbitrary "fl" variables inside the template context.

Attachments (1)

inclusion_tag.diff (1.2 KB ) - added by anonymous 18 years ago.

Download all attachments as: .zip

Change History (3)

by anonymous, 18 years ago

Attachment: inclusion_tag.diff added

comment:1 by nick@…, 18 years ago

On further consideration this feels a bit messy to me, it ends up cleaner to just use loader.render_to_string() in the tag to manually render the template and return the result. Feel free to close.

comment:2 by anonymous, 18 years ago

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top