Score:1

Can I pass a view's exposed filter values to the next page?

us flag
DHB

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?

Score:0
cg flag

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 }}
DHB avatar
us flag
DHB
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.
Yuseferi avatar
cg flag
@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 :).
DHB avatar
us flag
DHB
Thank you @Yuseferi! I was actually able to do just that, and it worked exactly as we needed it to.
Yuseferi avatar
cg flag
@DHB no problem at all. if it works mark it as an correct answer to help peoples in the future please :)
DHB avatar
us flag
DHB
Thanks for the tip @Yuseferi. I've marked it.
mangohost

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.