Search code examples
drupalviewdrupal-8drupal-taxonomydrupal-contextual-filters

(Drupal 8) View display nodes with taxonomy term found in URL


Using Drupal 8

I have a working setup my problem is when I try to access a taxonomy term that is made up of two words.

Set up.

  • View : shows nodes of content type A
  • Has relationship (required) with a field in the content type that stores the taxonomy term (one or more terms need to be associated to each content type)
  • Has contextual filter (that uses previous relationship) to get the taxonomy term from the URL. The filter gets the default value from Raw value from URL with Path component: 2 , and it has Use path alias instead of internal because the URL has the taxonomy term name. It also has Specify validation criteria by Taxonomy term name by Transform dashes in URL to spaces in term name filter values so that fan-art can be correctly matched to taxonomy term fan art.

I have no problem with taxonomy terms made up of one word, it's the ones made up of two words that are giving me a headache, any ideas?


Solution

  • I gave up trying to understand why it doesn't work and resorted to using Has Taxonomy term ID instead.

    • The URL contains the taxonomy term ID so only a Contextual Filter is needed. In raw value the URL is taxonomy/term/[id] , so all that needs to be done is tell the Contextual Filter to Provide default value from Type Raw value from URL and Path Component 3. I also added a Specify validation criteria WhenThe Filter Value is available or a default is provided, of Validator Taxonomy term ID and chose the appropriate Vocabulary.