How do I programmatically render a view that has exposed filters?


You can use this code in custom block can also set permission.

 use Drupal\Core\Form\FormState; 
 use Drupal\views\Views; 
   $form = []; 
   $view_id = 'blog_landing_page'; 
   $display_id = 'page_1'; 
   $view = Views::getView($view_id);     
   if ($view) { 
 $form_state = (new FormState()) 
   'view' => $view, 
   'display' => &$view->display_handler->display, 
   'rerender' => TRUE, 
   $form_state->set('rerender', NULL); 
 $form = \Drupal::formBuilder()->buildForm('\Drupal\views\Form\ViewsExposedForm', $form_state); 
Tags: Views / Drupal 8

Similar questions

Programmatically get exposed filters from view
A little bit of context: I am running a headless Drupal 8 with React in the front-end. All the data gets exposed through various endpoints. Now i am trying to render a view in react, there was no problem in obtaining the data. But when i tried to get the exposed filters i ran into a problem (the filters are based on taxonomy terms). I expected to g...
How to get a view result programmatically without exposed filters respected
I have some views of display page which I do not want to show to public if there would not be any result when accessed without any exposed filters set. I have a custom views access plugin and a custom access checking class which can handle the access granting. My idea so far is that I would like to run the view a first time during access checking w...
Adding custom classes to Views Filters (view-filters) and Content (div.view-contents)
I'm using a theme that includes bootstrap. I'd like to inject class one_third into <div class="view-filters"> and two_third last to <div class="view-content">. Is there a way to do so from any theme theme_preprocess_area? I know I could accomplish using javascript (selecting div.view-filters and addClass()), but I think it would be most...
Printing views exposed sort criteria separately to exposed filters
Exposed filters are either: - Printed in views-view.tpl.php using the $exposed variable. - Printed in a block, probably using the same variable. This variable ($exposed) contains the exposed sort criteria and filters. I would like to find a way to print them separately. Ideally there would be a way to use something like: Does anyone know of a way y...
combine several exposed filters into one exposed (search) form?
Is there an easy way to combine two or more exposed filters into one shared exposed form? So that I don't have to have several search fields for each and every field that I want to filter. Is this possible? Any modules that does this? I am using the Better Exposed Filters module. Thanks in advance
Exposed filters and taxonomy. How to make a redirect to a term page when exposed form submit?
Let's say there are 2 vocabularies: pathauto sizes: /size/s, /size/m, ... pathauto colors: /color/red, /color/green, ... There is a catalog - taxonomy/term/% view with the following filters: If we use a filter, then the url will be like this - ?field_size_tid=2&field_color_tid=3 It's normal, when several fields are selected in the filter But wh...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.