0

We have a view, myview, that is added to the https://www.adomain.com/some-page/ page. It has an exposed filter, Topic that a person can use to filter the user where Ajax = Enabled so that it loads the results without refreshing the page.

The view is added to a landing page (content type = basic) and at the bottom of the page. It is meant to return nodes where topic tag value is equal to what is supplied from the url.

Taxonomy term values (topic):

  1. IoT
  2. Cloud
  3. Cloud Security

How to setup view to filter based on second URL parameter?

Expected behavior:

  1. Display all items when https://www.adomain.com/some-page/ is loaded.
  2. Display all items where topic = Cloud Security when https://www.adomain.com/some-page/cloud-security is loaded
  3. Display all items where topic = Cloud when https://www.adomain.com/some-page/cloud is loaded

Current Behavior:

  1. Displays all items when loading https://www.adomain.com/some-page/
  2. Displays no items when loading https://www.adomain.com/some-page/cloud

What we have tried using block display type:

  1. Create view using block display type with a contextual filter Content: topic
  2. When filter value is not available = Display all results for the specified field
  3. When the filter value is available or a default is provided is set to Specify Validation Criteria = enabled, Validator = Taxonomy Term Name, Vocabulary = topic, and Action to take if filter value does not validate = Display all results for the specified field

What we tried using Page display type:

setting

  1. add path /some-path (without %)
  2. Add relationship, field_topic: taxonomy term and require relationship = true
  3. Add contextual filter: Name from Taxonomy term (field_topic) with the following settings below.

Contextual filter settings:

not in the url

When the filter value is not in the URL

  • Display all results for the specified field

topic case more

When the filter value is in the url or a default is provided

  • Specify validation criteria = Validator = Taxonomy term name
  • Vocabulary = Topic
  • Transform dashes in URL to spaces in term name filter values = true
  • Action to take if filter value does not validate = Display a summary
  • Case = Lower case
  • Case in path = lower case
  • More = Transform spaces to dashes in url = enabled
3
  • Is this a content view, or taxonomy term view? Are you listing nodes or terms in your views results?
    – prkos
    Nov 12, 2018 at 23:57
  • @prkos updated the question to include this information. Basically it is a content view where the results are nodes where topic is equal to the one from the url. If the value is not added to the url then it should return all. Nov 13, 2018 at 0:05
  • Instead of using term name in contexual filter use "has taxonomy term"
    – user52318
    Nov 19, 2018 at 5:42

1 Answer 1

4

Content Views don't have access to Taxonomy term name information out of the box, you only have term ID available. So even if you add the Taxonomy term field as the contextual filter and set the Validator = Taxonomy Term Name you're not telling it what to use, you're basically making a mistake trying to use that validator.

You can test this if you enter the term ID into the Preview instead of the name, or set the Action to take if filter value does not validate to Display a Summary and see what you get as output ;)

Add term name info through Relationship

To introduce the term name information into your content views you have to:

  1. add a Relationship to the term: Taxonomy term referenced from field_topic. Require it if you only want to list nodes that have a topic assigned.

    Now you will see a new Category of fields when adding Contextual filters: Taxonomy term

  2. Add the Contextual filter Name from Taxonomy term Category, it will use the Relationship from previous step by default, and configure it:
    When filter value is not available
    Display all results for the specified field
    When the filter value is available or a default is provided
    Specify validation criteria
    Taxonomy term name
    [Case settings, other relevant config as you see fit]

You will now see all results when visiting the main path, and if you visit the path with topic name appended the list will be filtered to show only nodes with that topic.


In case you have terms with the same name accross vocabularies

There is a bug that kicks in sometimes when using term name as the Validator, if you have different terms with the same term name: TermName views argument_validator is not working as expected.

The patch from that issue is working, as reported by the question author usernameabc, so it can be used until a new version is released that includes it.

15
  • any reason why when use the Preview with contextual filters, if i add a value from the topic as long as it is a single word, it works. If i type cloud, it returns what I want. When i type cloud-security, then zero results (even when transform dashes in url to spaces in term names filters values = enabled). Also, when i visit https://www.adomain.com/some-page/, then it works, but when I navigate to https://www.adomain.com/some-page/cloud i get a 404 page. Any thoughts as to what else i am missing? Nov 13, 2018 at 0:59
  • 1
    There is one more option you need if you want dashes in URL: Transform spaces to dashes in URL under the last Fieldset More at the bottom of the contextual configuration popup. If Page is behaving differently from Preview, it's often about how the contextual argument is fed to the views. Do you have % appended to your Path? You probably need to remove it because you have set to show all results, and not provide a default. Also to debug: change to show a Summary instead of Page not found when the filter doesn't validate, then type some gibberish word and see the links you get in Summary.
    – prkos
    Nov 13, 2018 at 18:38
  • for some reason, enabling that setting worked, but it is only working for single word. When using cloud-security in the url, I get page not found, but if i used cloud, then it filters. Why would that be? Nov 13, 2018 at 23:44
  • See my last comment above, you didn't report back about debug with Summary. You should also probably post your contextual and other configuration, otherwise it's a guessing game.
    – prkos
    Nov 14, 2018 at 0:41
  • 1
    Yes that makes sense, and it is a bug, the Validator should mind the chosen Vocabulary. I was curious that if it maybe isn't the case of the same name in different Vocabularies it might be the smilar term name with a space inside (cloud and cloud-security), but it is that bug in the end. I hope they release the patched version soon and I'm glad you finally got it fully working.
    – prkos
    Nov 19, 2018 at 17:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.