0

I would like to make a master.html for inheritance, but my problem is that in 3 different places the code is the same except the body class.

So I have master.html

<html>
 <head>...<head>
 <body>
  {% block one %}{% endblock %}
  {% block two %}{% endblock %}
  {% block extra %}{% endblock %}
 </body>
</html>

But in some places I have <_body class="front"> <_body class="not_front"> The rest of my content (like .js files, images) is the same.

Is there any clean way do it right and not to have three different 'masters'?

1 Answer 1

1

You can define a block inside the <body> tag:

<html>
    <head>...<head>
    <body {% block body_options %}{% endblock %}>
        {% block one %}{% endblock %}
        {% block two %}{% endblock %}
        {% block extra %}{% endblock %}
    </body>
</html>

Then, in your child templates,

{% extends 'master.html' %}
{% block body_options %}class="front"{% endblock %}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.