Hi,
I am new to Django and I am still going through the tutorial. I've tried
to set up a context processor for the following scenario, and I would
like to obtain some confirmation if this is a proper solution or I am
doing some mess..
In my base template with a header there is a navigation bar. A single
button should be highlighted among the others depending in the current
section / page in the website:

<ul>
    <li><a href="/blog">Blog</a></li>
    <li><a href="/about"*class="selected"*>Projects</a></li>
    ...
</ul>

What I thought so far was to register a universal context processor:

def navbar_selected_menu( request ):
    items = {"blog": "", "about": ""}
    target = request.META["PATH_INFO"]

    def select( key ):
        " Select the given key in the dictionary item "
        nonlocal items;
        items[key] = ' class="selected"';

    if re.match( "(^/$)|(^/blog$)|(^/blog/)", target):
        select("blog")
    if re.match(  "^/about\.s?html", target): # about
        select("about")


    return {"navbar": {"selected": items}};

and add to all links a variable such as <a href="/blog"{{ navbar.selected.blog 
}}>Blog</a>.

Is this solution appropriate or does it exist something clearer?

Moreover, is there the chance to pass explicitly a variable from the url 
mapping to the context processor ?

Kind regards,
Dean


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/54D1543C.6050104%40gmx.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to