Twig name for field of view I have an view that uses the Unformatted list format and Show: fields.



I've added the fields to it and the view has _Content type: my_content_type_ filter.

I want to write a template file for the fields in that view, with the following code.

{% if field_name == 'field_photo' %}
    ...
{% elseif field_name == 'field_something_else' %}
&lt;div class="something"&gt;
    {% for item in items %}
        {{ item.content }}
    {% endfor %}
&lt;/div&gt;&lt;!-- .something --&gt;


I don't know which name to use for the template file.

I've tried the following names, but they don't work. MY_CUSTOM_TYPE stays for the content type I have set in filter for that view.


field--MY_CUSTOM_TYPE.html.twig
field--node--MY_CUSTOM_TYPE.html.twig


What is the correct filename for the template file I am trying to use?
You could use: 

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

Use the machine name if you only want to affect a specific view Display. (IE: when you click + Add button, that other view/display does not get affected). If you wan't all displays to be affected, then don't include the machine name.

views-view-fields--[view-name].html.twig

{% if fields.field_photo.content|striptags == 'some value' %}
    ...
{% elseif fields.field_something_else.content|striptags == 'some value' %}
&lt;div class="something-specific"&gt;
        {{ fields.field_something_else.content }}
&lt;/div&gt;&lt;!-- .something-specific --&gt;
{% endif %}


If you just want to add a div class regardless of the value of the field and not depending on some condition, then simply 

&lt;div class="something"&gt;{{ fields.field_machine_name.content }}&lt;/div&gt;

OR you can do this through the Views UI:



Now, if you need something more global, IE: You want to affect all Views that contain your field and future views that will contain your field, then you need to use:

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

&lt;div class="something"&gt;{{ output -}}&lt;/div&gt;