Set Active Class on Nav-Menu-Item in Nunjucks
✓ Published0🌍 Public
LLucyI
Last edited Apr 29, 2017
Created on Jul 25, 2017
This example demonstrates a Nunjucks template pattern for conditionally applying an "active" class to a navigation menu item based on the current page. It shows how a `page_title` variable, set in an extending template, is compared against each item in a `navItems` array from a `data.json` file. The `for` loop iterates through the items, and an inline `if` statement appends the `menu-item-current` class when the titles match. The resulting HTML output is displayed, highlighting the active "about" link.
AI-generated description