1

I have a view that lists some nodes, has some exposed filters, like countries and search and a registered path without any contextual filters.

I also have a second view with the same exact exposed filters, but with a different registered path, again without any contextual filters.

At the first view I have a link that points to that second view.

The question is how can I pass the filters values (if any) selected from the first view to that second view when I click to the link of the first view?

After trying some things didn't managed to solve that but only by using the $_SESSION variable, however I'm not sure how optimal is this?!

1

Option 1: Views Global Filter. I've never used it but it sounds like a good but very heavy solution.

Option 2: Create the url for the second view dynamically with jQuery every time the exposed filters are changed. If you disable Ajax in the second view, you can see the url change and then use that as basis. The url will still work if you switch on Ajax again.

Option 3: Tokenise the exposed filters and create the link like option 2 in the header or footer. There seems to be a couple of modules / sandboxes that could help.

I'd probably pick option 2 but of course, there are probably other solutions like your session variable and some views hook.

  • Nice list there. Note, that views hooks won't work as the $view object is being rebuilt any time a view is being displayed, in other words the latest filters values will never be available without storing them somewhere before they pass to an other view. As for the jQuery, what if the js is disabled for a browser? I don't think that is a good approach expect if I'm missing something. – mchar Dec 6 '16 at 13:25
  • Hmm...... This is a bit crazy.. If you want it to work without JS, then that means no Ajax views either. So the url of the first page, with the data in the url, can be a http_referer. So on the first view, you can probably create a regular link to some random page and then, have a module that would only fire on that page. The module would parse the http_referer, use that info to create a new url for the second view and then redirect to it. In the Views UI, you can rename exposed filters' url thing under its settings so they match the first page easily. It could actually work. – Niall Murphy Dec 6 '16 at 13:59
  • I'm taking what you said about the views hooks as 100% correct by the way.. I don't know enough about them so that's why I came up with that mess of a solution. – Niall Murphy Dec 6 '16 at 14:02
  • For the time being I'll stick to the $_SESSION approach, like you said I don't want to over complicate things. I never said that I am using ajax :) – mchar Dec 6 '16 at 14:24
  • Out of interest, how do you use $_SESSION? – Niall Murphy Dec 6 '16 at 15:12

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.