0

I have a view block that lists different nodes. If I am viewing the block on any of those pages I'd like to add an .active class (or at least some kind of identifier) to highlight it with CSS as a form of active trail.

I have no clue on how to do this though, and I can't really find any useful documentation for this either.

Should I do this in a template, within views UI? If i could get the current node ID views-view-fields--products--block-1.html.twig I could compare it to the individual row IDs i guess?

I've seen this patch, but I'd rather get a better understanding how I am supposed to achieve this myself than just adding a random patch.

3
  • Go for JS and compare the link of the item with the current URL.
    – leymannx
    Mar 1, 2021 at 18:44
  • Also means: I have no idea what .active should be referring to here. Clicked item? Current URL? Selected? Could be just CSS.
    – leymannx
    Mar 1, 2021 at 18:49
  • Drupal Menus do this automatically, I expected it might work in Views? If not, I'd add a Contextual ID filter but set it to show all results, just to get a token working about which node you're visiting and passing it to Views. Then you can use that token in the CSS class option under Style in Field settings. I haven't tried it, I'm just suggesting what you might try.
    – prkos
    Mar 2, 2021 at 11:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.