Skip to content

Instantly share code, notes, and snippets.

@mortendk
Last active November 3, 2022 10:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mortendk/f8f88446f59bffad06e40d7ed2b5368d to your computer and use it in GitHub Desktop.
Save mortendk/f8f88446f59bffad06e40d7ed2b5368d to your computer and use it in GitHub Desktop.
svg inside a link in drupal menus
{% import _self as menus %}
{#
We call a macro which calls itself to render the full tree.
@see http://twig.sensiolabs.org/doc/tags/macro.html
#}
{{ menus.menu_links(items, attributes, 0) }}
{% macro menu_links(items, attributes, menu_level) %}
{% import _self as menus %}
{% if items %}
{% if menu_level == 0 %}
<ul{{ attributes.addClass('L-space', 'width-75','width-100@s') }}>
{% else %}
<ul>
{% endif %}
{% for item in items %}
<li{{ item.attributes }}>
{% set description = item.original_link.getDescription()|split(' | ') %}
{% set linktitle = description.0 %}
{% set svgicon = description.1 %}
{% set menuitem %}
<span class="menu-main__icon _t_icon-use">
<svg>
<use xlink:href="/{{ active_theme_path() }}/templates/component/navigation/main/menu-icons.svg#{{ svgicon }}"></use>
</svg>
</span>
<span class="menu-main__title">{{ item.title}}</span>
{% endset %}
{{ link( menuitem|raw , item.url, { 'class': ['multiple', 'classes', 'here'], 'id':['i-canhaz-id'], 'hell': 'yeah!' } ) }}
{% if item.below %}
{{ menus.menu_links(item.below, attributes, menu_level + 1) }}
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
{% endmacro %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment