You are here

links.html.twig in Drupal 10

Theme override for a set of links.

Available variables:

  • attributes: Attributes for the UL containing the list of links.
  • links: Links to be output. Each link will have the following elements:

    • link: (optional) A render array that returns a link. See template_preprocess_links() for details how it is generated.
    • text: The link text.
    • attributes: HTML attributes for the list item element.
    • text_attributes: (optional) HTML attributes for the span element if no 'url' was supplied.
  • heading: (optional) A heading to precede the links.
    • text: The heading text.
    • level: The heading level (e.g. 'h2', 'h3').
    • attributes: (optional) A keyed list of attributes for the heading.

    If the heading is a string, it will be used as the text of the heading and the level will default to 'h2'.

Headings should be used on navigation menus and any list of links that consistently appears on multiple pages. To make the heading invisible use the 'visually-hidden' CSS class. Do not use 'display:none', which removes it from screen readers and assistive technology. Headings allow screen reader and keyboard only users to navigate to or skip the links. See http://juicystudio.com/article/screen-readers-display-none.php and http://www.w3.org/TR/WCAG-TECHS/H42.html for more information.

File

core/themes/stable/templates/navigation/links.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Theme override for a set of links.
  5. *
  6. * Available variables:
  7. * - attributes: Attributes for the UL containing the list of links.
  8. * - links: Links to be output.
  9. * Each link will have the following elements:
  10. * - link: (optional) A render array that returns a link. See
  11. * template_preprocess_links() for details how it is generated.
  12. * - text: The link text.
  13. * - attributes: HTML attributes for the list item element.
  14. * - text_attributes: (optional) HTML attributes for the span element if no
  15. * 'url' was supplied.
  16. * - heading: (optional) A heading to precede the links.
  17. * - text: The heading text.
  18. * - level: The heading level (e.g. 'h2', 'h3').
  19. * - attributes: (optional) A keyed list of attributes for the heading.
  20. * If the heading is a string, it will be used as the text of the heading and
  21. * the level will default to 'h2'.
  22. *
  23. * Headings should be used on navigation menus and any list of links that
  24. * consistently appears on multiple pages. To make the heading invisible use
  25. * the 'visually-hidden' CSS class. Do not use 'display:none', which
  26. * removes it from screen readers and assistive technology. Headings allow
  27. * screen reader and keyboard only users to navigate to or skip the links.
  28. * See http://juicystudio.com/article/screen-readers-display-none.php and
  29. * http://www.w3.org/TR/WCAG-TECHS/H42.html for more information.
  30. *
  31. * @see template_preprocess_links()
  32. */
  33. #}
  34. {% if links -%}
  35. {%- if heading -%}
  36. {%- if heading.level -%}
  37. <{{ heading.level }}{{ heading.attributes }}>{{ heading.text }}</{{ heading.level }}>
  38. {%- else -%}
  39. <h2{{ heading.attributes }}>{{ heading.text }}</h2>
  40. {%- endif -%}
  41. {%- endif -%}
  42. <ul{{ attributes }}>
  43. {%- for item in links -%}
  44. <li{{ item.attributes }}>
  45. {%- if item.link -%}
  46. {{ item.link }}
  47. {%- elseif item.text_attributes -%}
  48. <span{{ item.text_attributes }}>{{ item.text }}</span>
  49. {%- else -%}
  50. {{ item.text }}
  51. {%- endif -%}
  52. </li>
  53. {%- endfor -%}
  54. </ul>
  55. {%- endif %}