On Thu, 2007-04-05 at 00:05 +0000, Roboto wrote:
> Hey guys, just a quick question here:
> 
> I have a base template called base.html.  Essentially all it holds are
> blocks to be filled in by child templates and it contains a menu which
> is common to all templates but it is also in block in case I ever
> needed to override it in the future
> 
> So I have a view called news and all it does is fill in the content
> block with the latest news.
> 
> However, I've recently been working with sessions (so that a user can
> log in) and I want to be able to change some of the values in the Menu
> from when you are logged in or logged out, but I don't want to have to
> re-write the menu in every single view I've created just to
> incorporate this.
> 
> How do I go about doing this?

Write a custom template tag that receives the template context when it
is being rendered. If you use RequestContext() when calling your
template, that will include the request, which includes the session.
This template tag is responsible for creating the menu fragment.

If you use the inclusion tag shortcut, you can write the bulk of your
menu presentation as a template and have the logic controlling what to
display in Python code. See
http://www.djangoproject.com/documentation/templates_python/#inclusion-tags for 
some details and examples.

Regards,
Malcolm


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to