Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
By Mojtaba Reyhani on
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
Here are some answers...
OP posted same question on Stack Exchange:
https://drupal.stackexchange.com/questions/241864/how-can-i-add-custom-c...