views-view-grid.html.twig

Same filename in this branch
  1. 9 core/themes/stable9/templates/views/views-view-grid.html.twig
  2. 9 core/themes/stable/templates/views/views-view-grid.html.twig
  3. 9 core/themes/starterkit_theme/templates/views/views-view-grid.html.twig
  4. 9 core/themes/classy/templates/views/views-view-grid.html.twig
  5. 9 core/modules/views/templates/views-view-grid.html.twig
Same filename in other branches
  1. 8.9.x core/themes/stable/templates/views/views-view-grid.html.twig
  2. 8.9.x core/themes/classy/templates/views/views-view-grid.html.twig
  3. 8.9.x core/modules/views/templates/views-view-grid.html.twig
  4. 10 core/themes/olivero/templates/views/views-view-grid.html.twig
  5. 10 core/themes/stable9/templates/views/views-view-grid.html.twig
  6. 10 core/themes/starterkit_theme/templates/views/views-view-grid.html.twig
  7. 10 core/modules/views/templates/views-view-grid.html.twig
  8. 11.x core/themes/olivero/templates/views/views-view-grid.html.twig
  9. 11.x core/themes/stable9/templates/views/views-view-grid.html.twig
  10. 11.x core/themes/starterkit_theme/templates/views/views-view-grid.html.twig
  11. 11.x core/modules/views/templates/views-view-grid.html.twig

Theme override for views to display rows in a grid.

Available variables:

  • attributes: HTML attributes for the wrapping element.
  • title: The title of this group of rows.
  • view: The view object.
  • rows: The rendered view results.
  • options: The view plugin style options.
    • row_class_default: A flag indicating whether default classes should be used on rows.
    • col_class_default: A flag indicating whether default classes should be used on columns.
  • items: A list of grid items. Each item contains a list of rows or columns. The order in what comes first (row or column) depends on which alignment type is chosen (horizontal or vertical).

    • attributes: HTML attributes for each row or column.
    • content: A list of columns or rows. Each row or column contains:
      • attributes: HTML attributes for each row or column.
      • content: The row or column contents.

See also

template_preprocess_views_view_grid()

File

core/themes/olivero/templates/views/views-view-grid.html.twig

View source
  1. {#
  2. /**
  3. * @file
  4. * Theme override for views to display rows in a grid.
  5. *
  6. * Available variables:
  7. * - attributes: HTML attributes for the wrapping element.
  8. * - title: The title of this group of rows.
  9. * - view: The view object.
  10. * - rows: The rendered view results.
  11. * - options: The view plugin style options.
  12. * - row_class_default: A flag indicating whether default classes should be
  13. * used on rows.
  14. * - col_class_default: A flag indicating whether default classes should be
  15. * used on columns.
  16. * - items: A list of grid items. Each item contains a list of rows or columns.
  17. * The order in what comes first (row or column) depends on which alignment
  18. * type is chosen (horizontal or vertical).
  19. * - attributes: HTML attributes for each row or column.
  20. * - content: A list of columns or rows. Each row or column contains:
  21. * - attributes: HTML attributes for each row or column.
  22. * - content: The row or column contents.
  23. *
  24. * @see template_preprocess_views_view_grid()
  25. */
  26. #}
  27. {% if options.alignment == 'vertical' %}
  28. {{ attach_library('olivero/layout-views-grid-vertical') }}
  29. {% else %}
  30. {{ attach_library('olivero/layout-views-grid-horizontal') }}
  31. {% endif %}
  32. {% set columns = options.columns <= 8 ? options.columns : 8 %}
  33. {%
  34. set classes = [
  35. 'views-view-grid',
  36. 'views-view-grid--' ~ options.alignment,
  37. 'cols-' ~ columns,
  38. ]
  39. %}
  40. {% if title %}
  41. <h3>{{ title }}</h3>
  42. {% endif %}
  43. <div{{ attributes.addClass(classes) }}>
  44. {% for row in items %}
  45. {% for column in row.content %}
  46. <div class="views-view-grid__item">
  47. <div class="views-view-grid__item-inner">
  48. {{- column.content -}}
  49. </div>
  50. </div>
  51. {% endfor %}
  52. {% endfor %}
  53. </div>

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.