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.

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

{% if not header_after_exposed and header %}
  {{ 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.

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

Filed Under:

  1. Drupal Planet
  2. Drupal
  3. PatternLab
  4. Frontend Development