Opened 16 years ago

Closed 16 years ago

#11175 closed (wontfix)

Automatic template inheritance

Reported by: Denis Martinez <deuns.martinez@…> Owned by: nobody
Component: Uncategorized Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Sometimes I have templates in my framework that I would like to override (Satchmo for example).

So I copy the .html in my template directory.
The drawback is that I can't create a template.html in my project and extend with {% extends "template.html" %}, because that would mean recursive includes.

Copying is bad for maintainability and it duplicates template code. So I suggest a templatetag {% autoextends %} that would search the next template directories for a template to extend, with the same filename. Like so:

base_template/index.html:

{% block test %}Test{% endblock %}

derived_template/index.html:

{% autoextends %}
{% block test %}{{block.super}}. It works!{% endblock %}

Change History (3)

comment:1 by dc, 16 years ago

I think that implicity will lead to many strange errors.

Better add parent dir to the TEMPLATE_DIRS and use

{% extends "base_template/index.html" %}
{% block test %}{{block.super}}. It works!{% endblock %}

in derived_template/index.html

comment:2 by Denis, 16 years ago

This tag should exist at least for convenience; if you don't like it, you don't have to use it.

If the functionality is correctly implemented, I don't know what kind of errors you're thinking about.
The django code can (should) make sure that recursion problems will never happen.

Your solution seems hackish to me, possibly more error-prone. In this case you are imposing a restriction on the parent directory's name, that we have to take in consideration when deploying on multiple servers.

comment:3 by Alex Gaynor, 16 years ago

Resolution: wontfix
Status: newclosed

This templatetag is impossible, neither the context nor the tag knows the name of the template being rendered.

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