Skip to main content
Tweeted twitter.com/StackDrupal/status/1066074024319639555
added 53 characters in body; edited tags; edited title
Source Link
Yuseferi
  • 22.2k
  • 22
  • 118
  • 218

Insert code in views-view-unformatted.html.twig pattern name for specific rows in viewsoverride view templates

Twig template - views-view-unformatted.html.twigviews-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-blocksonly for certain views-blocks. Twig debugging offers me to theme a whole block (for example: block--views-block--news-left-block-1.html.twigblock--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.

Is it possible? Howwhat is the correct filename to override view template?

Thank you.

Insert code in views-view-unformatted.html.twig for specific rows in views

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

#}
{% 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.

Is it possible? How?

Thank you.

pattern name for override view templates

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.

Source Link
Jimm
  • 41
  • 1
  • 1
  • 3

Insert code in views-view-unformatted.html.twig for specific rows in views

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

#}
{% 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.

Is it possible? How?

Thank you.