views-view-grid.html.twig 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. {%
  28. set classes = [
  29. 'views-view-grid',
  30. options.alignment,
  31. 'cols-' ~ options.columns,
  32. 'clearfix',
  33. ]
  34. %}
  35. {% if options.row_class_default %}
  36. {%
  37. set row_classes = [
  38. 'views-row',
  39. options.alignment == 'horizontal' ? 'clearfix',
  40. ]
  41. %}
  42. {% endif %}
  43. {% if options.col_class_default %}
  44. {%
  45. set col_classes = [
  46. 'views-col',
  47. options.alignment == 'vertical' ? 'clearfix',
  48. ]
  49. %}
  50. {% endif %}
  51. {% if title %}
  52. <h3>{{ title }}</h3>
  53. {% endif %}
  54. <div{{ attributes.addClass(classes) }}>
  55. {% if options.alignment == 'horizontal' %}
  56. {% for row in items %}
  57. <div{{ row.attributes.addClass(row_classes, options.row_class_default ? 'row-' ~ loop.index) }}>
  58. {% for column in row.content %}
  59. <div{{ column.attributes.addClass(col_classes, options.col_class_default ? 'col-' ~ loop.index) }}>
  60. {{ column.content }}
  61. </div>
  62. {% endfor %}
  63. </div>
  64. {% endfor %}
  65. {% else %}
  66. {% for column in items %}
  67. <div{{ column.attributes.addClass(col_classes, options.col_class_default ? 'col-' ~ loop.index) }}>
  68. {% for row in column.content %}
  69. <div{{ row.attributes.addClass(row_classes, options.row_class_default ? 'row-' ~ loop.index) }}>
  70. {{ row.content }}
  71. </div>
  72. {% endfor %}
  73. </div>
  74. {% endfor %}
  75. {% endif %}
  76. </div>