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.
Daniel Sipos
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.
Comments
In reply to View in view ... by Christian Wanscher (not verified)
Hey Chris, yeah it is a bit
Hey Chris, yeah it is a bit too complicated and it's very difficult for me to help you like this.
Can you recreate your problem on a test environment you could give me access to? I could take a look like that...
D
In reply to Hey Chris, yeah it is a bit by admin
Hi Danny,
Hi Danny,
Sorry I didn't get back to you. Overwhelmed with work here.
In the end, the customer decided on something else, and I have been busy doing that. But I would still like to experiment with this for another time. To find out how and if it works, as anticipated.
I have no time to create the test site now. Maybe later.
Thanks,
It's doing my head in
Hi,
I know this is exactly what I need to do, I just don't quite understand the process. I have been trying to replicate it to a letter, but no joy. Do you mind elaborate it a bit, please?
In reply to It's doing my head in by Christian Wanscher (not verified)
Hey there, which part
Hey there, which part troubles you?
In reply to Hey there, which part by admin
View in view ...
Hi Danny,
It is a good question!
Here's what I want: one page with 4 different content types in unordered display, newest on top, in 4 div's. For this, I use Semantic Views, and a grid-4 (Omega theme) to split it up. I would like to use each of the 4 taxonomy terms as title for each 'square'.
I have created a view, as per you instructions, filtered on vocabulary and terms, limited to 10 items (per term?)
I have created a new view with fields tax terms (excluded from display), place above next view - Global View. The Global View field is configured to use the specified vocabulary and Page in Display. The Contextual filed is filled with "!1" (== Content: Has taxonomy term ID title), and saved.
In Filters, I have Published (Yes), and Tax terms (term 1, term 2, term 3, and term 4)
In Path, I have /information (which is the path, I want to use for the full display of all 4 terms)
In Contextual Filters, I have "Content: Has taxonomy term ID", in 'NOT IN' : Show "Page not found", in 'IS': "Specify validation criteria" -> Validator = Tax term, ticked the vocabulary, "Filter value type" = Term name converted to term ID, and ticked the "Transform dashes in URL to spaces in term name filter values"
Now, when I run a query om a term, say Term 1, the term is appended to the path, as in /information/term 1, and I can see the desired titles. So far, so good.
But on the /information path, I get nothing except "Page not found"
It escapes me how I can 'persuade' the view to produce all 4 terms at once, without altering the path, showing each term/category in each their separate div
I apologise for the this lengthy description, and hope you can make sense of it.
views field view...or EVA field...
Hi Danny
Thanks for the information. I have various scenarios that I need to resolve with entity references, maybe you can help me get started..?
I have two profile2 types that share a taxonomy term and when a member of one profile type is logged in I want them to be able to see a views list of profiles from the other type that share the same taxonomy term. In this case it is Teachers and Pupils that belong to the same School (the taxonomy term). I think this could be handled with either EVA module or views field view....any thoughts?
Ed
THANK YOU KIND SIR!!!
This just made my day. Wait, it made my week. No, wait, it made my entire summer! Thank you so much, Danny! This really works for me.
For those of you having trouble with this tutorial, simply follow it word by word. The only thing I had to do as an extra measure was to add the relationship
Content: Taxonomy terms on node
to the "grand" view to get the fieldTaxonomy term: Term ID
available.Awesome.. you saved my live
Awesome.. you saved my live :D
You're genius, thanks alot!
You're genius, thanks alot!
How to order views results in
How to order views results in this case, by created date of last node in term?
Thanks
Any other way except using Taxonomy Terms
There are 9 different content types. But no one has a Taxonomy Term. There are tons of content. Is there any other way to connect children and parent views except Taxonomy Terms?
Regards from Berlin, Germany
Still a good tip in 2019!
Hey, after a few headdesks, I finally got this -- did have to carefully read through your instructions a few times, but finally managed to get this the way I wanted it to (this really beats trying to theme a field template for for a field with multiple values, IMO).
Thanks!
Add new comment