This tutorial will illustrate how to use the Views Field View module to create a page that lists a number of taxonomy terms, and for each, a different View of nodes tagged with the respective term. In other words to have Views within a View. For this, I will describe my own experience in creating something like this.
I had a taxonomy vocabulary with a number of terms that contained a description and an image. These terms were assigned to nodes of course for categorisation. And i needed to have a page that displays all the taxonomy terms with their description, image AND nodes associated with them.
What you can achieve by default with a simple View is a list of the terms that repeat for every node they are associated with. This you can do by adding a relationship but it is not really useful in my case. Enter Views Field View.
I think this is a really cool module that allowed me to do exactly what I wanted. After I installed it, I quickly became happy. So this is what I did:
I created a View of all the nodes that are tagged with either of the taxonomy terms in the respective vocabulary. The View was set to display only the titles of the nodes but used a Contextual Filter to limit the results according to the term they are associated with.
You can easily achieve this by adding a Contextual Filter of the type
Content: Has taxonomy term ID. Under When the filter value is NOT available you check
Hide View and under When the filter value IS available or a default is provided you can
Specify validation criteria as
Basic validation. This will make sure not to display anything if there is no filter value.
OK, so once I had this simple View, I went to create my Taxonomy Term View (my grand View). After adding all my usual fields, I added a special one:
Global: View. To configure this is to tap into the functionalities of the Views Field View module - which are great. I chose the View I wanted to embed (the one that I had made earlier) and even the Display from that particular View.
Then, under Contextual Filters I added a filter to narrow down the results of this view. Here you can add a default one which would make the View repeat itself for each row of the grand View. But, what is really cool is that you can use tokens from the fields of the grand View for dynamic results.
So since my node View had a Contextual Filter applied to it that was based on the taxonomy term ID of the term it was associated with, I added a new field in my grand view: Taxonomy term: Term ID and excluded it from the display. Note that you have to position it before the field that is supposed to use this token (in my case the Global: View field).
Alrighty, so then I added the Contextual Filter to filter down on my embedded view. This was the ID of each taxonomy term listed in the grand View (you can find it under Replacement Patterns) so the end result would make the embedded View display different results under each taxonomy term. Pretty cool a?
Feel free to comment if you need additional help to create this or similar Views. You can also read about how you can add numbering to your View results.
Hope this helps.
Danny founded WEBOMELETTE in 2012 as a passion project, mostly writing about Drupal problems he faced day to day, as well as about new technologies and things that he thought other developers would find useful. Now he now manages a team of developers and designers, delivering quality products that make businesses successful.