0

We have a view page (path = /some-path/) that has an exposed filter called category. The detailed view setup is below. How would we hide the exposed filter if it is supplied from the url?

View setup:

Filter criteria:

filter

Settings:

  1. Operator = is one of (list of all tags term values)
  2. Filter type to expose = single filter

Advanced

advanced

  1. Require relationships for field_tags
  2. when the filter value is not in the url --> display all results for the specified field
  3. when the filter value is in the url or default is provided

    a. specify validation criteria -> validator -> taxonomy term name where vocabulary = tag

    b. action to take if filter value does not validate = display contents of no results found

    c. case = lower case

    d. more -> transform spaces to dashes in url -> enabled

Expected behavior:

  1. when /some-path/ is navigated to, then the exposed filter should show
  2. when /some-path/term-value/ is navigated to, it will filter the results and hide the exposed filter

Current behavior:

  1. navigating to /some-path, shows all results with the exposed filter displaying allowing a visitor to change it.
  2. navigating to /some-path/value2/ filters the results and displays the exposed filter.
5
  • Isn't the URL basically resolving to /taxonomy/term/{id}? That would make the second View simple.
    – Kevin
    Nov 20 '18 at 1:46
  • @Kevin we didn't include the {id} parameter because we are using the tag value name instead of the tid Nov 27 '18 at 19:18
  • But the ID is still there, behind the alias.
    – Kevin
    Nov 27 '18 at 19:36
  • @Kevin so if we had some-path/iot in the url, based on the view's setting it would be able to map iot to it's {id} and do any filtering? Nov 27 '18 at 21:05
  • 1
    Just like you can set a contextual filter for nodes by doing "Content ID from URL", because the system path is /node/{id} just like taxonomy system paths are /taxonomy/term/{id}. So perhaps the first path you can fake out with a Views page at that URL, and then customize the taxonomy view URLs... the TVI module sort of solves this problem I believe.
    – Kevin
    Nov 27 '18 at 21:30
1

Here's a clever way to do it without coding: use two different Views displays and embed one of them as View area into another's No results behavior and configure the contextual accordingly.

  1. Create the Page with the Exposed Filter but without the Contextual filter
  2. Duplicate that Page to create another Page display with the same Path, but make these changes:
    1. override the Filters and remove the Exposed filter
    2. override the Contextual filters and Add your Term name there with these settings:
      When the filter value is NOT available
      Display contents of "No results found"
      When the filter value IS available or a default is provided
      Specify validation criteria
      [your settings]
      Action to take if filter value does not validate
      Display contents of "No results found"
    3. Override the No results behavior, add View area and choose the first Page display under View to insert (the one with the Exposed filter). Save the View if you don't see that display as option at first.

This way you get the first page to kick in for /some-path and you see the exposed filter, but if you add a term name to the path and it validates /some-path/value2/ the second Page display kicks in and you don't see the Exposed filter, you see the contextual results.

If the argument doesn't validate, you see the first Page and allow users to choose the term from the Exposed filter. You can change that to something else if it makes more sense. The part that makes this views switching work is the first part of the contextual filter When the filter value is NOT available Display contents of "No results found" and the embedded View area.

2
  • this worked without any custom code as you mentioned. I have some other items to take care of, but i am able to hide filter on validation from url, but display it when not in the url. Nov 27 '18 at 20:03
  • I'm glad it's working :)
    – prkos
    Nov 27 '18 at 20:15
0

I am not sure it will help but you could check out the module "better_exposed_filters". It sets out to do this sort of thing.

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.