0

Using the debug function I have found only one template suggestion for view's exposed form:

form--views-exposed-form.html.twig

I need to make changes to particular view, but I dont have other default suggestions like:

form--views-exposed-form--view-name--display-name.tpl.php

Should I write a function like hook_views_exposed_form_alter()

1
  1. create exposed form filters template following this naming standard:
    views-exposed-form--{view-name}--{display-name}.html.twig

    to get the view-name you can get from Backoffice (Structure > Views > search for your view > then get machine name and repalce the underscore with dash - see image bellow)


    enter image description here
    so we get this template:
    views-exposed-form--media-gallery.html.twig

  2. put your static HTML(we will replace in next step) there and clear cache you'll find the new tempalte.

  3. if you want to print the exposed fitlers just put {{form} in your tempalte

    views-exposed-form--media-gallery.html.twig

    {{form}}
  4. but if you want to print each exposed fitler serpately follow this steps : (Structure > Views> search for your view > Edit > click on filter name under the FILTER CRITERIA > scroll down and copy Filter identifier input value > go back to the template and print your exposed filter one by one {{ form.$fitler name }}

    views-exposed-form--media-gallery.html.twig

    {#1.print 1st exposed fitler form element + label #}
    {{ form.field_thematiques_target_id }}
    
    {#2.print 2nd form element + label #}
    {{ form.field_type_media_value }}
    
    {#3.include all other form elment ex submit button but to prevent 
    duplication remove other one #}
    {{ form|without('field_thematiques_target_id','field_type_media_value') }}
    
|improve this answer|||||
  • Thank you, I can also use views-exposed-form--{view-name}--{display-name}.html.twig – adpo Jan 16 at 7:10

Your Answer

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

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