views:

286

answers:

3

Hello,

I have a base template file which is base.html and every other template extends to it and generates content using its blocks.

Now, at my base.html file I want to include a variable that will be using some variable such as querylist.

In example:

assume I hav some NavigationObject model and at the base.html I want to loop through it and generate navigation links such as:

Say I have this querylist:

nav_obj = NavigationObject.objects.all()

At the base html:

{% for object in nav_obj %}
<a href="{{ object.link }}">{{ object.title }}</a>
{% endfor %}

For any view, I need to pass this nav_obj while rendering, istead of this, is there any way to globally declear to be used without passing for every view ?

Thanks

+5  A: 

Write your own context processor.

Ignacio Vazquez-Abrams
Thanks! Good details here : http://www.b-list.org/weblog/2006/jun/14/django-tips-template-context-processors/
Hellnar
A: 

You can also look at Django-navbar for it's documentation and tests..

dartdog
A: 

Inclusion tags might be a good-looking alternative to a context processor.

speakman