Working on my first Django project. New to templates and inheritance.
I'm using Bootstrap and want a splashy homepage. So I don't want sidebars, just Jumbotron. But, my index.html inherits from base.html and displays my sidebars which I do want in every other page but my home page. I want everything else, nav, footer, etc. to inherit.
My base.html:
{% block right_panel %}
blah blah blah
{% endblock %}
Is there a way to not inherit this block in my index.html? Or do I make a standalone index.html template with all of the block from base.html minus those I don't want to display?
What's best practice?
EDIT
Here's the offending piece in base.html:
<div class="col-md-3 right">
{% nevercache %}
{% include "includes/user_panel.html" %}
{% endnevercache %}
<div class="panel panel-default">
<div class="panel-body">
{% block right_panel %}
{% ifinstalled mezzanine.twitter %}
{% include "twitter/tweets.html" %}
{% endifinstalled %}
{% endblock %}
</div>
</div>
</div>
The CSS is rendering: <div class="panel-body">
My page.html:
{% extends "base.html" %}
<!-- no right-panel content-->
{% block right_panel %}{% endblock %}
{% load mezzanine_tags keyword_tags %}
{% block meta_title %}{{ page.meta_title }}{% endblock %}
{% block meta_keywords %}{% metablock %}
{% keywords_for page as keywords %}
{% for keyword in keywords %}
{% if not forloop.first %}, {% endif %}
{{ keyword }}
{% endfor %}
{% endmetablock %}{% endblock %}
{% block meta_description %}{% metablock %}
{{ page.description }}
{% endmetablock %}{% endblock %}
{% block title %}
{% editable page.title %}{{ page.title }}{% endeditable %}
{% endblock %}
{% block main %}
{% endblock %}
When I add:
`{% block right_panel %}{% endblock %}
to the top of page.html, the content doesn't render.
What's the best approach? Should I make a new block and wrap it around the that is being styled and then leave it empty in other templates? Or should I move the offending chunk from base.html to another template file and include it on pages where I want it rendered.
Also, another thing. If I remove {% block right_panel %}{% endblock %}
from page.html and put it in gallery.html which inherits from page.html, the content still renders.
Just declare the block as an empty block in your index.html to 'mute' the content from the base.html:
ie, in index.html:
...
{% block right_panel %}{% endblock %}
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With