I installed the Twig Tweak module on my site to render Views on the home page.

I want to make the display mode frontpage_tasks for the current user, his account, his stores and his groups.

{{ drupal_entity('user', user.id, 'frontpage_tasks') }}
{{ drupal_view('accueil_page_liste_des_taches_boutique', 'block_1') }}
{{ drupal_view('accueil_page_liste_des_taches_groupe', 'block_1') }}

Here is one of my Views :


The problem is that the Views module adds a lot of unnecessary markup that makes it impossible to display it correctly.

I just want to make the display mode, without any additional tags.

How to do this ? Is there a Twig code to render only Views without the additional View tags ?



I created an views-view--accueil_page_liste_des_taches_boutique.html.twig template. It only contains the following code :

{{ rows }}

I display the Views blocks with the code below, on my homepage :

                <div class="main-timeline">
                  <div class="row">
                    {{ drupal_entity('user', user.id, 'frontpage_tasks') }}
                    {{ drupal_view('accueil_page_liste_des_taches_boutique', 'block_1') }}
                    {{ drupal_view('accueil_page_liste_des_taches_groupe', 'block_1') }}

I still have this damn markup :

                <div class="views-element-container">

Is there a code in TWIG to remove this basisage ?


  • 2
    Views are rendered with their own twig templates. You can override them like any other template to tune the markup to your liking.
    – sonfd
    Jan 14 at 14:16
  • Notice that all this markup is not unnecessary if you are using views features like ajax reloading, exposed filters, pagination, facets or similar.
    – Hudri
    Jan 14 at 14:28
  • I rewrote the Views with the template views-view.html.twig, but there is still a completely useless div and views-element-container removed. How can I do ? ibb.co/pRb9sxs
    – user101865
    Jan 15 at 5:15
  1. You can enable Twig debugging for your site in sites/default/services.yml
        debug: true 
  1. Clear cache
  2. Inspect element in the browser and you will see the path to the template
  3. Copy the template to your custom theme's templates/ directory and adjust the markup
  • I updated my question
    – user101865
    Jan 15 at 17:03

For override view template, you should override (views-view.html.twig) this is template for all views.

If you want override only one specific view then copy code from views-view.html.twig to:

[base template name]--[view machine name].html.twig

example: (views-view--partners--block-1.html.twig)

and override this view as you want

enter image description here


You should add suggestions for views using this patch https://www.drupal.org/files/issues/views-template-suggestions-2839945-2.patch recommended here https://www.drupal.org/project/drupal/issues/2839945 in order to see twig suggestion in debug html, additional you should enable the twig debug as mention above

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy