victorpavlov
9/30/2016 - 1:02 PM

svg inside a link in drupal menus

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 %}