0

I have a view that uses the Table format.

I want to add row classes like this:

  • Row 1: .row1
  • Row 2: .row2
  • Row 3: .row3

In the Views UI, if I click Settings under Format: Table, then I can specify the Row class. This field allows tokens, but I can't find a token that refers to the views row itself.

How can I implement a row class that assigns a number based on the position of the row in the view?

  • @NoSssweat Yes, that's what I wanted to ask. Let's close this as a dupe. – Patrick Kenny Sep 22 at 16:11
1

There are plenty of ways to go about this question, my suggestion is overriding twig templates.

You would need to override the Twig template for that view. If you enable debug, clear cache, inspect element, you will see the template for that view. Then for that twig file, just use the loop index

loop.index  The current iteration of the loop. (1 indexed)

to track which row you are in.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.