Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x

toolbar-button.twig

{# Extra classes variable added to be sure that modifiers will
appear after main classes #}
{%
  set classes = [
    'toolbar-button',
    icon ? 'toolbar-button--icon--' ~ icon : '',
  ]
%}

{% if modifiers is iterable %}
  {% set classes = classes|merge(modifiers|map(modifier => "toolbar-button--#{modifier}")) %}
{% endif %}

{% if extra_classes is iterable %}
  {% set classes = classes|merge(extra_classes) %}
{% endif %}

{% if text and text|length > 1 %}
  {# We take the first two letters of the button text to use as a fallback when
  the toolbar button does not have a pre-assigned icon. #}
  {% set icon_text = text|slice(0, 2)|join('') %}
  {% set attributes = attributes.setAttribute('data-index-text', text|first|lower).setAttribute('data-icon-text', icon_text) %}
{% endif %}

<{{ html_tag|default('button') }} {{ attributes.addClass(classes) }}>
  {% if action %}
    <span data-toolbar-action class="visually-hidden">{{ action }}</span>
  {% endif %}
  {% block content %}
    {% if text %}
      <span class="toolbar-button__label" data-toolbar-text>{{~ text ~}}</span>
    {% endif %}
  {% endblock %}

</{{ html_tag|default('button') }}>

File

core/modules/navigation/components/toolbar-button/toolbar-button.twig

View source
  1. {# Extra classes variable added to be sure that modifiers will
  2. appear after main classes #}
  3. {%
  4. set classes = [
  5. 'toolbar-button',
  6. icon ? 'toolbar-button--icon--' ~ icon : '',
  7. ]
  8. %}
  9. {% if modifiers is iterable %}
  10. {% set classes = classes|merge(modifiers|map(modifier => "toolbar-button--#{modifier}")) %}
  11. {% endif %}
  12. {% if extra_classes is iterable %}
  13. {% set classes = classes|merge(extra_classes) %}
  14. {% endif %}
  15. {% if text and text|length > 1 %}
  16. {# We take the first two letters of the button text to use as a fallback when
  17. the toolbar button does not have a pre-assigned icon. #}
  18. {% set icon_text = text|slice(0, 2)|join('') %}
  19. {% set attributes = attributes.setAttribute('data-index-text', text|first|lower).setAttribute('data-icon-text', icon_text) %}
  20. {% endif %}
  21. <{{ html_tag|default('button') }} {{ attributes.addClass(classes) }}>
  22. {% if action %}
  23. <span data-toolbar-action class="visually-hidden">{{ action }}</span>
  24. {% endif %}
  25. {% block content %}
  26. {% if text %}
  27. <span class="toolbar-button__label" data-toolbar-text>{{~ text ~}}</span>
  28. {% endif %}
  29. {% endblock %}
  30. </{{ html_tag|default('button') }}>

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal