VivaNosh
VivaNosh

Reputation: 47

django template inheritance use same tag multiple templates

I am using the django template system fine-though is there a way to use the same variable inheritance tag for more than one template without pulling in the data from the other template too.

<div id="content-container3">

{% block content-container2 %}{% endblock %}

</div>

So I want to use the above in say people.html template and test.html template.

for example: {% extends "base.html "} {% block content-container2 %}{% endblock %}

Though it cross refernces information from two templates in this case -does each variable inheriatnce tag have to be unique?

Upvotes: 1

Views: 608

Answers (2)

Shivansh
Shivansh

Reputation: 1

I think you should try nesting blocks like the below example.

{% block first_section %}
    {% block first_section_upper %}
      {{block.super}}
    {% endblock first_section_upper %}

      <h1 class="display-5">Some content</h1>
      <h5 style="color: white !important;" class="display-5"> *Your text here*</h5>

      <p class="lead">The Algorithms that run our Universe</p>

    {% block first_section_lower %}
      {{block.super}}
    {% endblock first_section_lower %}
{% endblock first_section %}

The h1 tag and p tags can be different for every new template. As far as i could understand, this might solve your problem.

Upvotes: 0

chmeliuk
chmeliuk

Reputation: 1078

try to move this part of code to different file (content_container3.html) and use include tag... or I did not understand your question :)

Upvotes: 0

Related Questions