Skip to content

Cannot reach multiple levels up in template hierarchy with super #928

@eteq

Description

@eteq

I asked about this on #pocoo and got no answer. I'm fairly sure it's not possible, which means this is probably a feature request?

There does not not seem to be any way to get multiple-levels up in a super() call in a template. That is, if I have template C that extends B and B extends A, I want a super from C that skips the block in question from B and goes straight to the super from A.

(I know one answer is "don't do the super in B", but in this case it's impossible because A and B are from an external package)

Expected Behavior

a.templ

...
{% block body %}
  {% for complex in complicated %}
    <span>
    ... something complex using {{ complex }} that I don't want to have to reproduce...
    <span>
  {% endfor %}
{% endblock %}
...

b.templ

{% extends "a.templ" %}
{% block body %}
  <div class="something_I_dont_need">
    {{ super() }}
  </div>
{% endblock %}

c.templ

{% extends "a.templ" %}
{% block body %}
  <div class="something_I_actually_DO_need">
    {{ super(2) }}  # Or maybe {{ super("a.templ") }} ?
  </div>
{% endblock %}

Actual Behavior

Impossible to do, because c.templ has no access to the "body" block from a.templ without going through b.templ (which has parts I don't want)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions