Dnia 08-09-2010 o 15:41:13 Goran <[email protected]> napisaĆ(a):
Thanks for your help but I think that understand how template works.
My menu is drop down menu with menu items which comes from variable
{{ for menuitem in myvariable }}
<a href="menuitem.get_absolute_url">{{ menuitem.title }}</a>
{{ endfor }}
and myvariable is in my view:
myvariable = Item.objects.all()
So if I extend base.html menu is there, but menu items are not,
because "myvariable" come from the "view". So seems that I need
"myvariable = Item.objects.all()" in every view on the site. Which
also means that I need to repeat myself about 20 times. I was
wondering is there any solution to include myvariable in settings file
or something? Also is there any solution to extend flatpage view with
myvariable?
Thanks
http://docs.djangoproject.com/en/1.2/ref/templates/api/#subclassing-context-requestcontext
You can write ur own context processor, witch variables will be accessible
across all templates.
Example code:
content.py file:
from nml.newsletter.forms import NewsletterForm
def newsletter_form(request):
"""
Creates unbound newsletter form
"""
nl_form = NewsletterForm()
return {'nl_form' : nl_form}
in settings.py:
TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.contrib.messages.context_processors.messages",
'static_content.newsletter_form',
)
I used that once in root template, but it is rendered with any view that
extends my root template
--
Linux user
--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.