Right out front, I am working with Drupal 8.3.1.

I have a view that uses the table output format. One of the fields it outputs is a multi-value date field in the content type. It takes all the dates and puts them into an <ul> element that it then renders in the table cell.

I want to be able to preprocess that date field, to assign classnames to the individual <li> elements in it. I've tried to use template_preprocess_views_view_field, but by the time that fires, the list has been built and rendered to HTML and is presented as a #markup value.

I've looked at various other preprocess hooks and none of them seem to be able to let me hook in and do this. Is this a limitation of Views? Or am I missing something.


In the settings of the view field you can use this option (located in STYLE SETTINGS):

[x] Use field template

Now the field is rendered by the same field template you use in the content type including preprocess hooks.

To see the added theme hook and field template enable Twig debug and look at the html source in the browser.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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