1

I'd like to have this URL structure on a Drupal 8 site:

/schools/usa -> handled by custom view
/schools/europe -> handled by custom view
/schools/school-name -> handled as a normal node

So basically when the users makes a request for a URL like /schools/%, Drupal first checks if it finds a node with that alias and, if it doesn't exist, passes on to the view (or vice-versa, view first and then node if the view argument doesn't validate).

Is this achievable?

If I try, the view gets the precedence and throws a 404 on /schools/school-name as "school-name" fails to validate as a taxonomy term (it's a node title after all...)

1 Answer 1

2

Yes, you can do this. The key is in the Action to take if filter value does not validate option of your Contextual filter.

Set that option to Display contents of "No results found".

Then under No results behavior add Rendered entity - Content enter schools/{{ arguments.name }} or which ever correct token is in your case.

This will make your views work with regular terms, but if the term doesn't validate it will go to the page with the argument. In your case if the argument is school-name then it will lead to the node page with that path.

What you should additionally consider is what an argument is entered that isn't neither, a term nor the appropriate part of a node path. You'll just get a blank page with View page title.

Maybe you can solve that by adding another No results behavior for that case, maybe a block with a message that the term doesn't exist and a link back to the Views page, then hide the Block on your node pages that share the starting path string.

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.