Code

Opened 5 years ago

Closed 5 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: UI/UX:

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 %}

Attachments (0)

Change History (3)

comment:1 Changed 5 years ago by dc

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

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

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

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

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.