Apologies, this is pretty basic. I have abstracted my static html navigation bar to a block so that it can be dynamically rendered from a model. I have created a new block marker in base.html with the following syntax
{% block navigation %}{% endblock %}
How can I ensure this is rendered on every page? Do I need to create some sort of middle layer for this? Everything I have done so far has simply used the primary block.
EDIT Sunday, 14 August 2011 11:25 AM
I didn’t explain this very well. The content of navigation block is
{% extends 'base.html' %}
{% block navigation %}
<nav>
<ul>
{% for item in items %}
<li><a href="{{ item.url }}">{{ item.name }}</a></li>
{% endfor %}
</ul>
</nav>
{% endblock %}
I want to render this on every page without having to go through child templates of base.html individually and add it to them, if that is possible.
You have got static navigation bar, so you can just write code in your base.html page and then use it with
{% extends 'base.html' %}tag on every new page. Your markup will be in every page. Also, if you use only extends tag in your child page and then render it – you will see base.html without any edition.If you have got code, which need to appear on few pages, but not on everyone – create ‘includes’ directory, save code there and extend your base template with
{% include %}tag. It won’t avoid repating, but make your code shorter.And last thing you’ll need in future, maybe with dynamic code – caching. With
{% cache %}tag you can cache block for some time.