I'm trying to put the if/else statement to my base.html file. The idea is to have if/else as a part of the template that will be an extension for my HTML files. The problem is, I'm not sure what syntax would look like.
Previously, I had an HTML page (called the essay-page) with some content and if/else statement hardcoded to this particular page. But I want to have if/else as a part of my template too, so I could use it with several pages.
Essay-page with hardcoded if/else:
{% block body %}
{% if essay_found %}
<article>
<img src="" alt="">
<section id="location">
<h2>Other infos</h2>
<address>This essay was made in <span>LOCATION</span> (ADDRESS).</address>
</section>
<section id="details">
<h2>What's this essay about?</h2>
<p>{{ essay_description }}</p>
<footer>
<p>Need more details? <a href="">Please contact me</a> (but don't spam ;))</p>
</footer>
</section>
<section id="registration">
<h2>Send me your request and job offers!</h2>
FORM
</section>
</article>
{% else %}
<h2>No essay found for this slug, sorry! </h2>
{% endif %}
{% endblock%}
now I try to put this if/else to my base.html (without a success):
<main>
{% block body %}
{% if essay_found %}
{% block article %}{% endblock %}
{% else %}
<h2>No essay found for this slug, sorry! </h2>
{% endif %}
{% endblock %}
</main>
and update essay-page to:
{% block body %}
{% block article%}
<article>
<img src="" alt="">
<section id="location">
<h2>Other infos</h2>
<address>This essay was made in <span>LOCATION</span> (ADDRESS).</address>
</section>
<section id="details">
<h2>What's this essay about?</h2>
<p>{{ essay_description }}</p>
<footer>
<p>Need more details? <a href="">Please contact me</a> (but don't spam ;))</p>
</footer>
</section>
<section id="registration">
<h2>Send me your request and job offers!</h2>
FORM
</section>
</article>
{% endblock %}
{% endblock%}
I'm not sure if the problem is related to the lack of super block on the essay-page (because the blocks would be nested), or the syntax of if/else statement in base.html.