0

In D8 I have created two custom content types:

  1. Store
  2. Store products

It's not an e-commerce, I just need two custom types to show all the stores on one of the subpages and the products that each store has.

Because there are 24 stores, I would hate to create 24 custom types of a store products, so I also added a taxonomy term field to a Store product.

Now, I would want to show the Store products in a Block, depending on the taxonomy term.

For example: I created Store A, which has products A1, A2, A3. If I go to the page of Store A, there should be a block that shows those products.

If I would go to Store B, the same block would show products of Store B.

I tried following this answer and added a contextual filter, but no luck so far: Display content based on URL

What I did:

  • Created a View Block for Store Products
  • Added a contextual filter to the block (Has taxonomry term -> taxonomy term ID from URL)
  • Also added another contextual filter node:id
  • Added the block under blocks to render on the page Store

enter image description here enter image description here

  • Its probably better if you describe what you also did try, some code or views setup description. – GiorgosK Mar 4 at 12:00
0

What you're trying to do already come out of the box in "Taxonomy term" content views.

If you have tagged your Store product nodes with taxonomy terms these nodes will appear on the related term pages. You don't need a separate Block, the term pages will show a list of nodes tagged with that term.

You don't even need the Store content type if its whole purpose is to provide categorization. The "Store" Taxonomy Vocabulary is all you need.

Can you try and see if that is enough for you?


In your Contextual configuration you should use the option "Load default filter from term page", and not "Load default filter from node page" because the information is taken from the taxonomy term page, you're not showing a block on a node page.

Why do you need the second Contextual for NID? This is usually used when you want to exclude the current node from the list (Under More > Exclude), but you're not on a node page so there is nothing to comare the NID to. Remove that second Contextual, you don't need it.

  • Thanks for clarifying some things to me. I changed the filters as you proposed, but I still can't get the block to show. The reason why I created content type for store also is because I need to have a different logo and some text content for each one. And then, based on the name of the store, the "store products blocks" should render items that belong to that store - based on the taxonomy term. Or at least that's what I thought should be the easiest way to do it. – prima Mar 5 at 7:36
  • As you said, I tried and am able to do it with taxonomy terms only. I added some fields to taxonomy term to describe the store, and the products are listed automatically. – prima Mar 5 at 8:30
  • 1
    Those are all entities, you can add fields to Taxonomy terms just as you would to Content types! And you can show them in Views just like you would if the Store were nodes. Simply add the relevant fields to your Vocabulary, and inside Views add the Relationship for the field that connects your nodes to the Taxonomy terms. When you add that relationship you'll be able to show taxonomy term logo and description as fields, filters, what ever you need. The procedure would have been the same if Store were nodes, you'd still have to add the Relationship for that entity reference field. – prkos Mar 5 at 16:41

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.