Opened 5 years ago

Closed 2 years ago

#13984 closed New feature (duplicate)

template.loader.select_template should return template_name as well.

Reported by: DaNmarner Owned by: JoshStegmaier
Component: Template system Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The whole purpose of this function is to find out which possible location of a certain template is valid. It make sense to return the compiled template as well as its location.

Here's a common use case:

A template is found by select_template, however, this template extends an "base.html" whose is located in the same directory, which is unknown until runtime as well. So the extends tag fails.

If select_template returns the location of the template it finds, then this info could be passed into an context and thus make the extends tag useful again.

Attachments (2)

0001-Added-template_name-as-a-return-value-of-django.temp.patch (1.7 KB) - added by DaNmarner 5 years ago.
Added template_name as an return value to select_template
0002-template_name-as-optional-return-value-of-django.temp.diff (1.8 KB) - added by JoshStegmaier 5 years ago.
Adds option to return template name with select_template and documents change.

Download all attachments as: .zip

Change History (9)

Changed 5 years ago by DaNmarner

Added template_name as an return value to select_template

comment:1 Changed 5 years ago by DaNmarner

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from template.select_template should return template_name as well. to template.loader.select_template should return template_name as well.

The whole purpose of this function is to find out which possible location of a certain template is valid. It make sense to return the compiled template as well as its location.

Here's a common use case:

A template is found by select_template, however, this template extends an "base.html" whose is located in the same directory, which is unknown until runtime as well. So the extends tag fails.

If select_template returns the location of the template it finds, then this info could be passed into an context and thus make the extends tag useful again.

Changed 5 years ago by JoshStegmaier

Adds option to return template name with select_template and documents change.

comment:2 Changed 5 years ago by JoshStegmaier

  • Owner changed from nobody to JoshStegmaier
  • Status changed from new to assigned

In order to maintain backwards compatibility, it would probably be better if returning the template name was optional. I've attached a patch that would accomplish this.

comment:3 Changed 5 years ago by JoshStegmaier

  • Triage Stage changed from Unreviewed to Design decision needed

comment:4 Changed 4 years ago by graham_king

  • Severity set to Normal
  • Type set to New feature

comment:5 Changed 3 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:6 Changed 3 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:7 Changed 2 years ago by aaugustin

  • Resolution set to duplicate
  • Status changed from assigned to closed

The pattern used to change the result type isn't elegant...

It seems to me that #16096 provides the same information with a better API.

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