Skip to content

Instantly share code, notes, and snippets.

@startinggravity
Created October 30, 2015 15:37
Show Gist options
  • Save startinggravity/45a51cade33968fadcf4 to your computer and use it in GitHub Desktop.
Save startinggravity/45a51cade33968fadcf4 to your computer and use it in GitHub Desktop.
Use a Drupal menu as a social media links block
{#
/**
* @file
* Theme override to display a social media links from a menu.
*
* Available variables:
* - menu_name: The machine name of the menu.
* - items: A nested list of menu items. Each menu item contains:
* - attributes: HTML attributes for the menu item.
* - below: The menu item child items.
* - title: The menu link title.
* - url: The menu link url, instance of \Drupal\Core\Url
* - localized_options: Menu link localized options.
*/
#}
{% 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 %}
<ul class="menu--social-media__links">
{% for item in items %}
<li{{ item.attributes.addClass((item.title)|clean_class) }}>
<a href="{{ item.url }}" title="{{ item.title|t }}"><span class="visually-hidden">{{ item.title }}</span></a>
</li>
{% endfor %}
</ul>
{% endif %}
{% endmacro %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment