eudicots / Cactus

Static site generator for designers. Uses Python and Django templates.
BSD 3-Clause "New" or "Revised" License
3.47k stars 313 forks source link

Highlight active page in the navigation? #150

Closed paulba closed 9 years ago

paulba commented 9 years ago

Hi! I'm new to cactus and python and I can't find an answer for this anywhere. How can I apply a custom css class on a navigation list item depending on the current active page? Do I need a plugin for this?

Thanks

krallin commented 9 years ago

Use the if_current_page built-in template tag, like this:

<li class="{% if_current_page '/index.html' 'active' 'inactive' %}">Home</li>

This will apply the active CSS class if the current page is the one from ./pages/index.html, and inactive otherwise.

Note that you can of course replace 'inactive' with just '' if you'd rather not apply anything in case the current page isn't the one you're looking for.