Render a fulltext exposed search bar separate from the rest of the filters

cn flag

I would like to render my exposed fulltext search bar in a separate location from the rest of my search filters. My other exposed search filters are things like display number, sort order, etc... I am also using facets.

My current problem is that I need to render the search bar in a whole separate region from the rest of my exposed filters. My current solution is to render {{ exposed }} twice but then use CSS to display: none the items I don't want. This is just awfully hacky and is bad practice. Is there a way to split these forms into two separate exposed filters?

sa flag

You can render one by one by:

{{ exposed.filter_1}}
{{ exposed.filter_2}}

And group them as your wish.

About the render {{ exposed }} twice as your current solution, The items you don't want can be removed at the .twig, not CSS such:

{{ exposed|without('filter_1', 'filter_2') }}
Rubix05 avatar
cn flag
Thank you for your response! This has gotten me closer for sure. I am currently rendering my filters like this which visually achieves what I am looking for: {{ exposed|without('filter_1') }} {{ exposed|without('filter_2') }} The main problem though, because "exposed" is a render array containing a form. The two forms (with identical ids) are conflicting with each other. As an example, if I change the display setting, then the textfield resets its value, and if I change the textfield, then the other fitlers are reset to their defaults as well. Ajax is getting confused as well.
Trà Dương avatar
sa flag
You should take a look at `core\modules\views_ui\templates\views-ui-expose-filter-form.html.twig`. It display same filter form with separated parts by using {{ xxx|without('yyy') }} way. Besides, you can mix both (render one by one + render using |without) as my comment. Search `form|without` in Drupal core can give you some suggestions.
Rubix05 avatar
cn flag
Ah, I see what you are referring to! So this works in the filter form; however, the exposed variable is actually in the views-view.html template. I was actually able to utilize this rendering of separate elements in the form template as you have described because I lucked out and it worked with my layout. It does require me to inject a custom slider view inside of the exposed filter form to make it look like my design. BUT IT WORKS! For other cases, I may not get so lucky if the exposed filters need to be rendered in completely different regions.

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.