0

I am using a node to represent a subsite on my website. The node has just two fields: titleand field_subsite. The titles are all listed on the front page.

The subsites are constructed using a View: I.e.: Each leaf node has a taxonomy field, which hold the subsite identifier. I use a contextual filter in a page View that picks up the subsite identifier to display a page with all the nodes that belongs to a particular subsite. For example: example.com/subsite/1 shows all the nodes belonging to subsite with taxonomy term 1. All this works fine.

However, the missing bit is that when the user clicks on the title on the front page that identifies a subsite, they are taking to the node with the subsite identifier exposed. They have to click on this to see the actual subsite with taxonomy term 1.

Is there a way to set this up so that when clicking on title, the user is taken directly to the subsite represented by that title.

So far, all this has been created in the UI, but I guess that I should be able to solve this by implementing hook_node_view() and redirecting to the view from there?

However, I would like to know is there is a better solution.

2
  • What kind of view is it? If it's a block, just use layout builder to override the default view mode for the node and show the view instead. Jun 13 at 14:36
  • @PatrickKenny It is a page view, because I pass the TID in the URL (e.g. example.com/subsite/1). Added this extra information to the question. If I do it with a block view (in order to use core's Layout Builder), how to I get the TID passed to the View? Jun 13 at 15:12

1 Answer 1

1

The way I see it, you have two options here:

  1. Replace the front page with a view of nodes, in the view render fields, and set the title of the display to link to the subsite for the node.

  2. Use outbound link re-writing to rewrite node links to the subsite: https://www.drupal.org/node/2238759

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.