1

My question is exactly the same as View block not accepting contextual filter argument but I'm unable to comment and the question never received a valid answer.

I want to know if it is possible to achieve this functionality: A view block is placed on a node and shows all results by default. The node path is /community/blog. /community/blog/106 will display the same node with the placed view block, except the view block is filtered to content associated with the TID in the third path component.

Like the previous question, I do have this configured to work in the view preview. However /community/blog/106 leads me to a 404. This makes sense because how can Drupal know that for that particular path formation, it should first attempt to pass the 3rd path component to the view on /community/blog/ as an argument, and if it succeeds, display /community/blog/ with the filtered view, and if it fails... Who knows what?

It seems to me that this functionality does not exist, even though the Views UI would lead you to believe it does. It exists if you're using a view page but NOT a block. This confusing usability problem exists because the contextual filter options that work with a view page are not removed for view blocks (Unless I'm wrong, which I would love to be). As in the previous question, it does not always make sense to completely throw your site layout out the window in order to have a view page that can accept path arguments. Does anyone know if what I'm asking for is possible using a view block?

  • The difference is that Views pages build routes, Views blocks do not. So you need to define a route somewhere else, for example in a yaml file, so you are not getting a 404 and the additional path component resolves to a route. You could also add a dummy Views page display only to build the route, which otherwise just displays the single node. Then you would have all in one place and don't need a custom module for the route. – 4k4 Sep 18 '18 at 21:20
  • Thanks for the reply! Could you explain what you mean by a dummy Views page display? If a page display is enabled and set to the same path alias as the node, wouldn't it take precedence over the node? Guess there's only one way to find out... – maskedjellybean Sep 19 '18 at 22:05
  • No, it would only match a path with the TID added as third path component. – 4k4 Sep 20 '18 at 6:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.