Hi,

On Mon, 2008-06-02 at 08:46 -0700, Will wrote:
> Hi all
> 
> I'd like to start a discussion about generating navigation components.
> Despite their importance and their fairly generic nature, best
> practice is not obvious to me after trawling through hundreds of
> posts, blogs etc.
> 
> Anyone that's interested, could you briefly state how you do it,
> perhaps answering the following questions?
> 
> A. Where do you get the information about the site structure?
>     E.g. Do you just have a static include file, perhaps store it in
> the db, or work it out from URL confs?
> 
> B. How do you deal with indicating the current page in the nav
> component?
> 
> This is what I'm thinking of doing -
> 
> A. Generate a two level nav component from my URLConf file, then cache
> it heavily. I'm looking at using the name from named url patterns to
> populate the anchor lables.
> 
> B. Use javascript (window.location.href or something) to change the
> class of the current page element. This will be much quicker to
> implement and not too obtrusive on failure.

I've written a block tag which will take care of adding a class to the
HTML output.

* mark_current block tag
    Adds class="mark" to the leftmost HTML tag if a matching href="" tag
    has been found in the same line for the currently requested path.

    Already assigned classes are conserved.

    Example:
    <ul>
    {% mark_current %}
    <li><a href="/whereever/">Whatever</li>
    <li><a href="/something/">Something else</li>
    {% endmark_current %}
    </ul>

You'll find it here:
http://spinlock.ch/pub/git/?p=django/feinheit.git;a=tree
in file templatetags/navigation_extras.py

The code is somewhat hacky and does not do everything I need yet, but
it's working great for many sites. Feel free to use/steal it if it fits
your needs.

-- 
http://spinlock.ch/blog/

--~--~---------~--~----~------------~-------~--~----~
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