I have a D8 site view with exposed filters. I want the selected filters from that view to carry over to the next page's URL.

For example: The page lists software titles. If someone filters on OS, and picks MacOS, the URL of the view page changes from "viewpage" to "viewpage?os=MacOS". I want to make the links in the view change from "drupalpage" to "drupalpage?os=MacOS".

I can't figure out how to add the "?os=MacOS" query string to a link in the view. Is there a way to do that?


I think what you needed to get in on your preprocess and pass it to your views.

In a hook_preprocess_views_view() implementation in your theme or module:

$values = $view->getExposedInput();
// for example $values["os"];

Or, you can access the values directly from the views-view.html.twig template:

// Assuming `os` is configured to be the Filter identifier in the 

// view's Filter Criteria exposed filter.
{{ view.getExposedInput.os }}
  • Thanks. I was asking about the filter variables in the URL being passed into the links on the page so they would persist on the next page, and BEF (which we're using) doesn't do anything like that. We did figure out how to do what I needed in the TWIG template for the page by using view.getExposedInput variables there. Works perfectly.
    – DHB
    Sep 25 at 12:44
  • @DHB thank you very much for your comment. I miss understood the question. I update the answer for you it's a bit late but it could help other drupalist who need something like it in the future :).
    – Yuseferi
    Sep 26 at 11:49

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.