andunhill
andunhill

Reputation: 61

djangocms template inheritance

Django-cms multiple inheritance does not work.

I have the following template structure:

base.html
    {% block content %}
    {% endblock content %}

page1.html
    {% extends "base.html" %}
    {% block test %}
    {% endblock test %}

page2.html
    {% extends "page1.html" %}
    {% block content %}
          <div>foo</div>
    {% endblock content %}
    {% block test %}
          <div>foo</div>
    {% endblock test %}

The problem is that the block test in page2 HTML is not rendered. Only the blocks from base.html are rendered. If I include block test in base.html is also gets rendered in page2

Upvotes: 0

Views: 407

Answers (2)

Spacedman
Spacedman

Reputation: 94237

base.html is your top level template. This would normally be the thing that starts with an html doctype and ends with a </html> tag. Everything else has to have a place to go in there. All you have is a content block.

So where would the test block go? You've tried to put it in page1.html, but it still needs a place to go in the parent template.

Upvotes: 0

Caspar
Caspar

Reputation: 410

Does your base.html contain {% block test %}?

Your base template must contain the block you want to override. You can add additional blocks in child templates, but they must be contained within a base block.

See https://docs.djangoproject.com/en/dev/topics/templates/#template-inheritance

Upvotes: 1

Related Questions