If you use Meteor Router or a similar routing solution, you might want to give navbar links an active class when you're on that page. If you're trying Template helpers, you're probably going about it the wrong way. It couldn't be simpler to register a custom Handlebars helper.

First, we define a method that gets the current path. This simply returns the path without a / at the end, or just / if we're at the root path:

// Get the current path for URL curPath=function(){var c=window.location.pathname;var b=c.slice(0,-1);var a=c.slice(-1);if(b==""){return"/"}else{if(a=="/"){return b}else{return c}}};

Next, we'll register the helper. Notice the closure as the second argument? This is what we will enter when we use the helper in our view. Then we just check to see if our path argument matches the actual path of the current page, and return "active" if that's the case. Easy:

// Determine if current link should be active Handlebars.registerHelper('active', function(path) { return curPath() == path ? 'active' : ''; });

Now we can use it in our view:

<ul class="nav"> <li class="{{active '/'}}"> <a href="/">Home</a> </li> <li class="{{active '/some/page'}}"> <a href="/some/page">Some Page</a> </li> <li class="{{active '/about'}}"> <a href="/about#faq">FAQ</a> </li> ... </ul>

Voila!

For an excellent set of handy helpers, check out raix's excellent Meteor Handlebar Helpers package.