By Sifro


2019-02-09 15:36:24 8 Comments

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 comments

@prkos 2019-02-09 16:00:32

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.

Related Questions

Sponsored Content

0 Answered Questions

D8 - Can 2 Entities share the same name?

  • 2018-05-17 09:27:38
  • mogio
  • 27 View
  • 2 Score
  • 0 Answer
  • Tags:   8

3 Answered Questions

1 Answered Questions

[SOLVED] Create View with a join on the same content type

  • 2016-03-30 02:59:36
  • jetmanz
  • 55 View
  • 3 Score
  • 1 Answer
  • Tags:   views

2 Answered Questions

How to add a term ALIAS(!) to content URL pattern?

  • 2015-08-01 08:13:16
  • Alex777
  • 189 View
  • 2 Score
  • 2 Answer
  • Tags:   path-aliases

0 Answered Questions

0 Answered Questions

Automatic alias pattern to accommodate node hierarchy and menu items

  • 2015-02-11 03:13:35
  • Frank H.
  • 353 View
  • 0 Score
  • 0 Answer
  • Tags:   path-aliases

1 Answered Questions

[SOLVED] Drupal extra subdomains for some special nodes

0 Answered Questions

Linking Page manager & views using taxonomy terms

1 Answered Questions

[SOLVED] Drupal 7 aliases for a certain content type producing 404

  • 2011-07-21 08:40:10
  • Will
  • 877 View
  • 0 Score
  • 1 Answer
  • Tags:   uri path-aliases

Sponsored Content