Score:0

How to show content / blocks in views for path component 3, 2 OR 1?

ec flag

The taxonomy contains mostly 3 levels, sometimes two levels only.

Parent
  Child 1
    Grandchild 1
  Child 2

Via path alias, the patterns create URLs like:

/parent/child1/grandchild1
/parent/child2

When I configure my views block with the logic for the grandchild and place this blog into the layout builder of the taxonomy, it's working like a charm. enter image description here

Only when I hit the the URL of the child (not grandchild) I get the error:

Drupal\Core\Database\InvalidQueryException: Query condition 'taxonomy_term_field_data.name IN ()' cannot be empty. in Drupal\Core\Database\Query\Condition->condition() (line 117 of core/lib/Drupal/Core/Database/Query/Condition.php).

(which seems to make sense, since there is not 3rd component in my path - /parent/child2)

How to "catch" the request without a 3rd component or how can I validate either component 3 or 2 (and I'd need 1 as well in some cases).

unusedspoon avatar
aq flag
The easiest way is just to have 2 blocks within your view. 1 looking for arg3 and 1 looking for arg 2
Chris avatar
ec flag
That would be fine. Issue is just the error. How to make sure, if there is no arg3, then I'd only show results for arg2?
mx flag
Settings for the contextual filter already give you that option. What did you choose below the Specify validation criteria? Do you have **2** Contextual filters, one for child, another for grandchild, in correct order, and with correct Relationships?
Chris avatar
ec flag
I couldn't get it working via the path. Now I'm using `Content: Has taxonomy term ID` as a contextual filter and it works directly for all depths and even with special characters.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.