0

I am doing some block experiments because I'm new in Drupal and I want to know if I can create a view block to place X(more than one) times in the same page with different results by taxonomy term content.

I have a new content type which its related(a field) to a taxonomy term, and I want to place the same block for each taxonomy term created and inside the block show the created content related to that taxonomy term.

Ex: Imagine you have a taxonomy term called "Vehicle type". We create two terms into "Vehicle type"(car and truck). Now I create a content type called "Vehicle info" and I create.

I create a new "Vehicle info" content with a field "Vehicle Type" and check Reference type -> Vocabulary -> "Vehicle Type".

So now I want only a Block which can be placed twice in the same page and each block must list "Vehicle type" contents (one will have cars and the other trucks list).

I tried with contextual filters but when I place the block it does not shows to choose cars or trucks terms.

Many thanks :D

1 Answer 1

0

What is the criteria according to which the two different blocks will "know" whether you want to show cars or trucks?


If you want to control this, and have two separate Blocks showing different term-related content, you can create two Blocks but add regular Filters to them, filtering to show content related to either cars or trucks. The add each separate Block where you want them in a theme region.


If you want an automatic solution where a contextual filter does everything, you usually want to show either cars or trucks, but not both on the same page. Contextual filter will "sense" the context, it will recognize something on the page you're currently viewing, and where you placed the Block, and it will pass this context info to your Views, and filter results according to it. This is commonly used to place Blocks on Node pages, where you want to show other content that has been tagged with the same term. For example you're viewing Car1 node, and want the Block to list all the other nodes that have also been tagged with the term "car", so you would see Car2, Car3 etc. Besides the Contextual filter to pull the related content, you will also want the second contextual filter that would exclude the current node from the list, because it doesn't make sense to the visitor to see it there. You will need to adjust Contextual settings when placing the Block in a theme region.


The third option may sound the closest fitting to your description: Create One Block listing all nodes of that type, add the Field for the Taxonomy reference field, and under Format use the Taxonomy reference field to "Grouping field Nr.1". This will list all content but it will be Grouped in clusters based on the "car" or "truck" tags. You can edit the Field and "Exclude from display" because you will see it in the group title. There is no need for Contextual filters here as you want to list everything, you only want it separate into groups. Place the Block in a theme region and adjust visibility...


You can add the same Block to display in Drupal as many times as you want, in the same theme region, or in a different place, but you can't make it behave differently. A Block with a Contextual filter can show different results only if the Context it's surrounded with is different. But if on the same page, the context is the same, and the result will be the same.

BTW the "Vehicle type" is a Taxonomy Vocabulary, and the "car" is a Taxonomy Term.

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.