What's the "right way" (or at least the options, if there is no single "Ember way" of doing this) for a navigation sidebar? Should I be looking at ContainerViews somehow, or should I just use the new outlet feature and stick the navigation inside my application view?
In addition, what's the "right way" to set an .active class on an li depending on the URL (I'm using routing)? Is there some kind of a helper for this?
I didn't like MilkyWayJoe's answer because if you sooner or later want to change the naming of your states or whatever you have to go through the code AND the view as well, also adding a function to transitionTo every route seems not desirable. My approach is a bit more programmatic and modularized:
nav-view.hbs (for twitter-bootstrap-style navs)
This way, I can just create and mess around with my routes in the Router, and keep the Nav-Definitions side-by-side:
<Update date="2013-01-16">
The previous examples are no longer valid since the recent changes in the Router API, so I'm not going to fix those. All applications using the old router should migrate as soon as possible to the latest.
Here's an updated fiddle: Source | Live Demo
I will be maintaining/fixing/adding features every so often.
Edit on Apr 3rd 2013:
Alternative Sample - WIP: source | demo
ALL CONTENT BELOW IS DEPRECATED
<Update>
2012-Nov-09
Just adding a link to a better sample that also addresses the part which the OP wants to set a class in the current navbar item when a given route is selected
Source in JSFiddle (Click here to see it running)
If you look in the NavigationController you'll see the 'selected' property, which I use to check in the isActive method of the child view NavigationItemView. The isActive will return true or false based on the value in the
menu
property of the same view (defined in the template) and the value in the propertyselected
(of the controller). Then check the classNameBinding expressions which either sets 'active' or nothing to the class of that particular child. Also check the ConnectOutlets which is where I'm marking that nav item as selected.This is running on ember-latest. I'm also using a little of Ember.Bootstrap as well as some of the original Twitter Bootstrap features/classes/etc (but I've replaced the styles with metro-bootstrap).
Not pasting the whole thing here because of space and all. I will leave the original code and link to the same for reference to the original question/answer.
I'll keep updating this new sample just because ember is fun =)
</Update>
This fiddle shows a static navbar from a view, and the outlet is used only for content display, or you can go directly to the display to see it running
As you can see, you can use a simple view containing your action links and have this view rendered in you application main view. The sub-routes under "starting" also have a mini navbar, coming from a similar template.
Handlebars:
JavaScript: