You are here

item-list.html.twig in Drupal 9

Theme override for an item list.

Available variables:

  • items: A list of items. Each item contains:

    • attributes: HTML attributes to be applied to each list item.
    • value: The content of the list element.
  • title: The title of the list.
  • list_type: The tag for list element ("ul" or "ol").
  • wrapper_attributes: HTML attributes to be applied to the list wrapper.
  • attributes: HTML attributes to be applied to the list.
  • empty: A message to display when there are no items. Allowed value is a string or render array.
  • context: A list of contextual data associated with the list. May contain:
    • list_style: The custom list style.

File

core/themes/bartik/templates/classy/dataset/item-list.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Theme override for an item list.
  5. *
  6. * Available variables:
  7. * - items: A list of items. Each item contains:
  8. * - attributes: HTML attributes to be applied to each list item.
  9. * - value: The content of the list element.
  10. * - title: The title of the list.
  11. * - list_type: The tag for list element ("ul" or "ol").
  12. * - wrapper_attributes: HTML attributes to be applied to the list wrapper.
  13. * - attributes: HTML attributes to be applied to the list.
  14. * - empty: A message to display when there are no items. Allowed value is a
  15. * string or render array.
  16. * - context: A list of contextual data associated with the list. May contain:
  17. * - list_style: The custom list style.
  18. *
  19. * @see template_preprocess_item_list()
  20. */
  21. #}
  22. {% if context.list_style %}
  23. {%- set wrapper_attributes = wrapper_attributes.addClass('item-list--' ~ context.list_style) %}
  24. {%- set attributes = attributes.addClass('item-list__' ~ context.list_style) %}
  25. {% endif %}
  26. {% if items or empty -%}
  27. <div{{ wrapper_attributes.addClass('item-list') }}>
  28. {%- if title is not empty -%}
  29. <h3>{{ title }}</h3>
  30. {%- endif -%}
  31. {%- if items -%}
  32. <{{ list_type }}{{ attributes }}>
  33. {%- for item in items -%}
  34. <li{{ item.attributes }}>{{ item.value }}</li>
  35. {%- endfor -%}
  36. </{{ list_type }}>
  37. {%- else -%}
  38. {{- empty -}}
  39. {%- endif -%}
  40. </div>
  41. {%- endif %}