If anyone could point me in the right direction I would be forever grateful. I cannot seem to make this work.

I have created a dozen or so product pages. I have also created a taxonomy term of each product name under the heading 'Products'. I would like to display assets relating to each product at the bottom of the product page. I have created a content type 'Asset' where I can enter a link to each asset, for example 'whitepaper', 'webinar' and 'video' and also included a field for the Taxonomy, where is can enter the names of the relevant products. I hope that's clear so far. I then made a block view and pulled the relevant fields from the Asset entries (asset type, name, link etc.), placed the block to display at the bottom of the main content block layout, and this all seems to be working just fine except it is of course displaying all assets for all products on all product pages. Now, what I need is a contextual filter that will display relevant assets to the product page. I have attempted to use contextual filters to make this work but to no avail. I have tried to use the contextual filter 'Has taxonomy term ID' and make it reference the url (where the product name is the second part of the address (/products/product). Clearly I'm not getting this right. Perhaps there is some relationship I need to add?

I feel I have tried every angle and so any recommendations would be extremely helpful.

Comments

Stefan Lehmann’s picture

I think if I understand you right you also have to create a relationship between a product and the corresponding product taxonomy term.

Generally trying to filter views based on string values encoded in a URL are very error prone and don't work very well.

This HOWTO-guide here is for D7, but should also work for D8:
https://scito.ch/content/show-related-nodes-block-based-taxonomy-terms-v...

I would also think about why you need that intermediate Taxonomy. If it's not really needed I'd probably remove it and have a direct relationship between Assets and Products .. But maybe you have good reasons for that?

Ah: the example might not work exactly like this as it's using a term reference field which doesn't exist in D8 anymore. But the solution should be similiarish.

I like cookies!

wezwest’s picture

Thanks Stefan. I tried the link you gave and I still can't make it work. But, your comment led me down another path and got me thinking. Am I just going about this all wrong? I am new to Drupal and don't fully understand all the functionality. How would you suggest I list these assets on a product page? Should I be using a reference field on the product page with a reference field view to pull these assets? Again thanks for the help.