Printing Regions in Views in Different Places Using the Same Template

We had a case where on some views we needed to print the header above the exposed filters and on others we needed to print the header after the exposed filters. Here's my simple solution.

markconroyWed, 04/10/2019 - 12:08

This is rather simple, in my views template (list.twig I call it, as I am using PatternLab), I created the following:

  1. {% if not header_after_exposed and header %}
  2. {{ header }}
  • {% endif %}
  •  
  • {% if exposed %}
  • {{ exposed }}
  • {% endif %}
  •  
  • {% if header_after_exposed and header %}
  • {{ header }}
  • {% endif %}
  • Now, in my corresponding views template in Drupal - views-view--search.html.twig - I just use that template and set the header_after_exposed variable to true.

    1. {% set header_after_exposed = true %}
    2. {% include '@content/list/list.twig' %}