Skip to content

Instantly share code, notes, and snippets.

@thamas
Created April 29, 2016 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thamas/7a3e45f8b2b62c5b08d23d1296e5bf6b to your computer and use it in GitHub Desktop.
Save thamas/7a3e45f8b2b62c5b08d23d1296e5bf6b to your computer and use it in GitHub Desktop.
add class to links
{# Create CSS class #}
{%
set link_classes = [
'c-menu-' ~ menu_name|clean_class ~ '__link',
]
%}
<li{{ item.attributes.addClass(item_classes) }}>
{# In link function add link class and remove leaking item classes #}
{{
link(
item.title,
item.url,
item.attributes.addClass(link_classes).removeClass(item_classes)
)
}}
{% if item.below %}
{# Pass menu_name as an argument to the macro #}
{{ menus.menu_links(item.below, attributes, menu_level + 1, menu_name) }}
{% endif %}
</li>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment