views-view-grid.html.twig 2.4 KB

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