1

I am trying to override the field rendered in a view. The field name is: this_is_field

I copied the /core/modules/views/views-view-field.html.twig and placed it my theme folder.

I renamed with both methods below

views-view-field--this-is-field.html.twig
views-view-field--display-name--block-name--this-is-field.html.twig

I have turned on Twig debugging and still the copied template isn't working.

Am I renaming wrong?

  • Is that the suggestion pattern? – Kevin Nov 23 '18 at 17:17
  • @Kevin What do you mean? – pierostz Nov 23 '18 at 17:49
  • @pierostz updated my answer – No Sssweat Nov 26 '18 at 9:56
2

It needs to be:

views-view-field--[field-machine-name].html.twig

If you look in Manage Fields, your field machine name is probably field_this_is_field.

Therefore, in your case:

views-view-field--field-this-is-field.html

Note that this is will override for all views that have this field, if you want to only target a specific view use:

views-view-field--[view-machine-name]--[field-machine-name].html.twig

  • The first method worked like a charm. How about the second...meaning what is the [view-name]? – pierostz Dec 3 '18 at 10:11
  • @pierostz the name of your view, if your view is called "Cool Items" then you add there cool-items – No Sssweat Dec 3 '18 at 10:18
  • Ok got it working. – pierostz Dec 3 '18 at 10:26
0

I tried second method from above answer and it didn't work. What works for me is views-view-field--[view-name]--[field-machine-name].html.twig

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.