3

Twig template - views-view-unformatted.html.twig contains :

#}
{% if title %}
<h3>{{ title }}</h3>
{% endif %}
{% for row in rows %}
{%
set row_classes = [
default_row_class ? 'views-row',
]
%}
<div{{ row.attributes.addClass(row_classes) }}>
{{ row.content }}
</div>
{% endfor %}

I want to insert a <hr> tag after each </div>:

<div{{ row.attributes.addClass(row_classes) }}>
{{ row.content }}
</div>
<hr>
{% endfor %}

It works, but for all and every {{ row.content }}. I want to do it only for certain views-blocks. Twig debugging offers me to theme a whole block (for example: block--views-block--news-left-block-1.html.twig) and I need something like views-view-unformatted--news-left-block-1.html.twig or some other way to insert the tag.

what is the correct filename to override view template?

Thank you.

4

Just use views-view-unformatted--(your view block name).html.twig. Eg. If your view name is Slideshow, use views-view-unformatted--slideshow.html.twig

This is a good reference point - http://redcrackle.com/blog/drupal-8/theme-views-templates

1

The pattern for override view template is

views-view-DISPLAYNAME--VIEWS_MACHINENAME--DISPLAY_MACHINENAME.html.twig

if you don't consider --DISPLAY_MACHINENAME the template will be used for all displays on VIEWS_MACHINENAME view.

in your case

DISPLAYNAME = unformatted
DISPLAY_MACHINENAME = news-left
DISPLAY_MACHINENAME = block-1

So your file pattern is

 views-view-unformatted--news-left.html.twig     

or

views-view-unformatted--news-left--block-1.html.twig

Note : if your machine name contain "_"(underscore) convert all of them to "-".

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.