Is it possible by using the theme preprocessor add some classes to views generated rows?

For example: based on Drupal site about default theme implementation to display a view of unformatted rows.
views-view-unformatted.html.twig:

Available variables:

  • - title: The title of this group of rows. May be empty.
  • - rows: A list of the view's row items.
  • - attributes: The row's HTML attributes.
  • - content: The row's content.
  • - view: The view object.
  • - default_row_class: A flag indicating whether default classes should be used on rows.

I know that it's possible and we can add our desired classes to each row inside the views-view-unformatted.html.twig:

{% if title %}
  <h3>{{ title }}</h3>
{% endif %}
{% for row in rows %}
  {%
    set row_classes = [
      default_row_class ? 'views-row',
    ]
  %}
  <div{{ row.attributes.addClass(row_classes) }}>
    {{ row.content }}
  </div>
{% endfor %}

But I want to understand is it possible to do the same thing for custom views like front-page by using of: template_preprocess_views_view_unformatted__frontpage or in other template_preprocess_views_view generally?

Comments

featherbelly’s picture