N2.Web.Tree current item class

Topics: Developer Forum
Feb 20, 2009 at 4:28 AM
I've just started looking at a real world implementation of the MVC example.

I really like the idea of the N2.Web.Tree class as it’s a real time saver in producing ULs for navigation as in the example.

Practically though I'm not sure how much use it is unless there is some way of distinguishing the current item i.e. through the use of a class (like <li class="current">).

Is there some way of making this work or will I have to abandon using the N2.Web.Tree methods for navigation and iterate through the collection?
Coordinator
Feb 21, 2009 at 12:35 PM
You can insert custom css classes through the use of delegates. Take a look at the unit tests to see how.
Feb 22, 2009 at 2:06 AM

Thanks so a really simple example to set the current li to class=”selected” might be:
N2.Web.Tree.From(N2.Find.StartPage,2).ClassProvider(delegate(N2.ContentItem item){ return (N2.Find.CurrentPage == item)? "selected":"none"; })

The commented out DecorateLinks method in the tests looks to be an ideal helper. Has this been abandoned?

Coordinator
Feb 22, 2009 at 2:13 PM
I think you can use "LinkProvider". Look at the test CanChangeLinkProvider.