Opened 16 years ago
Closed 14 years ago
#7815 closed (wontfix)
Let Context handle include, extends and inclusion_tag template loading
Reported by: | Johannes Dollinger | Owned by: | nobody |
---|---|---|---|
Component: | Template system | Version: | dev |
Severity: | Keywords: | feature | |
Cc: | goliath.mailinglist@…, research@… | Triage Stage: | Design decision needed |
Has patch: | no | Needs documentation: | yes |
Needs tests: | yes | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
- Add a
loader
kwarg toContext
which should be something with aget_template(name)
function. Default would bedjango.template.loader
. - Provide
get_template()
andselect_template()
methods onContext
, use these in include, extends and inclusion_tag. - Cache templates in
Context
, optionally: provide a way to populate this cache. - Remove
ConstantIncludeNode
since caching would provide the same benefits and it causes problems with recursive includes.
This would fix
- #2949 - templating engine too tightly tied to TEMPLATE_DIRS in the settings
- #3544 - recursive includes
- #4278 - get_template should accept a dirs argument
- #6834 - support for templates to be loaded from dynamically-selected directories
Example:
class PrefixLoader: def __init__(self, prefix_list): self.prefix_list = prefix_list def get_template(name): from django.template.loader import select_template return select_template(['%s/%s' % (prefix, name) for prefix in self.prefix_list]) tpl.render(Context({}, loader=PrefixLoader(['a', 'b', 'c'])))
Attachments (1)
Change History (9)
by , 16 years ago
Attachment: | 7815.tplrf.diff added |
---|
comment:1 by , 16 years ago
Needs documentation: | set |
---|---|
Needs tests: | set |
patch -p0 tplrf.2.diff patch -p0 tplrf-tests.diff patch -p1 7815.tplrf.diff
mostly done. contains a test for recursive includes, but no tests for the loader feature yet.
comment:2 by , 16 years ago
Cc: | added |
---|
comment:3 by , 16 years ago
This would also fix #7931.
Forgot to mention in the ticket description: this is a backwards incompatible change. If you rely on compile time side effects (e.g. {% load %}) in included templates, that will break.
comment:4 by , 16 years ago
milestone: | → 1.0 |
---|---|
Triage Stage: | Unreviewed → Design decision needed |
comment:5 by , 16 years ago
milestone: | 1.0 → post-1.0 |
---|
comment:6 by , 16 years ago
Cc: | added |
---|
comment:8 by , 14 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
The three (remaining) individual tickets (#3544, #4278, #6834) are all good ideas, but an omnibus patch makes it really hard to evaluate which bits are fixing what. It's also an area that needs a lot of cleanup following the 1.2 template loader changes.
Closing wontfix, mostly as a procedural thing; we'd prefer to see single patches for single issues, or a merging of issues into a single ticket (resulting in the previous tickets getting closed).
depends on tplrf.2.diff and tplrf-tests.diff from #7806