Code

Opened 7 years ago

Closed 7 years ago

#3171 closed enhancement (invalid)

[patch] Support for dynamic values in inclusion_tag template name

Reported by: nick@… Owned by: adrian
Component: Template system Version: master
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

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

Download all attachments as: .zip

Change History (3)

Changed 7 years ago by anonymous

comment:1 Changed 7 years ago by nick@…

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 Changed 7 years ago by anonymous

  • Resolution set to invalid
  • Status changed from new to closed

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.