Active Class for Menus #11
joeworkman
started this conversation in
General
Replies: 1 comment
-
|
A somewhat more general situation is where you have a topbar with several drop down menus. Each dropdown menu has a title that we would like to highlight as well as the selected menu item, i.e., we would like something like |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This is a continuation of a discussion over at https://github.com/foundation/foundation-sites/discussions/12351#discussioncomment-1930388
@benthien had a question on how to add an active class to his menu items. It's a good question. Here is an example of how you could accomplish this. I think that this could be made better in time.
General Overview:
outputvariable in the front matter of every page. This will specifically define the path to the page when it's builtis_activemacro that we can use to determine if a page is active or not.pages/one.html
--- output: one.html --- {% block content %} {% include "nav.html" %} {% endblock %}macros/nav.twig
{% macro is_active(page, output) %} {% if output == page %}active{% endif %} {% endmacro %}partials/nav.html
{% from "nav.twig" import is_active %} <ul class="menu"> <li class="{{ is_active('one.html', output) }}"><a href="one.html">One</a></li> <li class="{{ is_active('two.html', output) }}"><a href="two.html">Two</a></li> <li class="{{ is_active('three.html', output) }}"><a href="three.html">Three</a></li> </ul>Beta Was this translation helpful? Give feedback.
All reactions