I found, that the div with the id "js-view-dom-id" comes from views-view.html.twig. As I want to render one view output without any of Drupals HTML markup, I already hunted down the contextual links, which I can turn of for a specific view. Then I set the view format to an unused format, and removed all unwanted HTML markup from this views template as well.

Now I get plain {{ content.field_x.0 }}-output from this view. The only element left I need to get rid of is before mentioned "js-view-dom-id". I could remove this from views-view.html.twig, but then I would remove it from all views.

Is there any way to remove this markup for only one specific view? To be precise, I am using a custom content view mode, if that makes any difference.

Thank you very much in advance!


Twig in views-view.html.twig looks like this:

set classes = [
dom_id ? 'js-view-dom-id-' ~ dom_id,
<div{{ attributes.addClass(classes) }}></div>

Is there any way to do something like:

{% if view mode is xy %}
// Do nothing
{%  else %}
<div{{ attributes.addClass(classes) }}>
{% endif %}

1 Answer 1


Yes, you can easily create an override for views-view.html.twig which will only apply to a single View.

Taking the example from Views template files:

View, named foobar. Style: unformatted. Row style: Fields. Display: Page.

  • views-view--foobar--page.html.twig
  • views-view--page.html.twig
  • views-view--foobar.html.twig
  • views-view.html.twig

So if your View is called "articles", you can use views-view--articles.html.twig to override the template for the whole View, views-view--articles--page.html.twig to target just a display named page for the same view, and so on.

  • 1
    Thank you very much. That works flawlessly! Sorrily I can't mark your anser as the right one, due to not having enough reputation here. Jan 30, 2020 at 19:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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