Drupal - How do I create a nested tree with terms & nodes with Views 3?

Thanks to refino, I found a nice solution using the following modules:

  • Views Tree
  • Views Field View

Below you find the explanation:

  1. First create a new Taxonomy (let's call it "Folder")
  2. Then, create a new content type (let's call it "Element") with a term reference field to the "Folder" taxonomy
  3. Create a new "Content" View (let's call it "Element View")
  4. Choose Field Display
  5. Add a Contextual Filter to your term reference field
  6. Create a new "Taxonomy" View (let's call it "Folder Tree")
  7. Add 2 fields (term name and term id). The second field can be excluded from display
  8. In Relation: add a "parent term"
  9. Add a third field (term id) and assign it to your parent relation. This field can be excluded from display
  10. Choose Format "Tree (Adjacency model)" and select in the parameters : Ordered list + Main field (your first tid), Parent field (your tid assigned to the parent relation). You now should have a nice tree with all your terms nested
  11. Add a 4th field "Global:View" (this comes with Views Field View) and choose your "Element view", display Master add [tid] in the Arguments textfield

Hope this help

Cheers

Edit by iStryker: This is what I got. The only thing I changed was make Element View a table view, and removed the default (row & strip) classes.

Image of the final product by iStryker


I created three views in Drupal 7.8 and Views 3 + Views Field, nesting one view into another using Include View, and I got such a result (attached). enter image description here

Step-by-step how to do it:

  1. Create vocabulary "Colors" and fill it in with tags.

  2. Create a new view of taxonomy nodes Colors - I call it "Nodes of Colors"

2.1 Format Table , Settings: Grouping field: Taxonomy term: Name

2.2 Advanced Contextual filters: Taxonomy term: Parent term

2.3 Advanced Relationships: Taxonomy term: Content using Color

2.4 Set Fields: Taxonomy term: Term ID, Taxonomy term: Name, (field_color) Content: Title

2.5 Filter criteria: Taxonomy term: Vocabulary (= Colors)

2.6 If you want you can also set "Exclude from display" for Term ID, Taxonomy term: Name

2.7 Set Path:/nodes-of-colors/%

2.8 Set no results behavior: Global: View area (we will come back to this later) 2.9 save

3.Create a new view of taxonomy nodes Colors - I call it "Nodes of Colors 2"

3.1 Format Table , Settings: Grouping field: none

3.2 Advanced Contextual filters: Taxonomy term: Term ID

3.3 Advanced Relationships: Taxonomy term: Content using Color

3.4 Set Fields: Taxonomy term: Term ID, Taxonomy term: Name, (field_color) Content: Title

3.5 Filter criteria: Taxonomy term: Vocabulary (= Colors)

3.6 If you want you can also set "Exclude from display" for Term ID, Taxonomy term: Name

3.7 Set Path:/nodes-of-colors-2/%

3.8 Set no results behavior: Global: none

3.9 Save

Go back and edit "Nodes of Colors" again

4.1 go to Set no results behavior: Global: View area

4.2 Set View to insert: View: nodes_of_colors2 Display: page

4.3 set Inherit contextual filters

4.4 save

5 Go back to Views again (Type Term)

5.1 Create a new view of taxonomy nodes Colors - I call it "Colors Tree"

5.1 Format Table , Settings: Grouping field: none

5.2 Advanced Contextual filters: none

5.3 Advanced Relationships: Taxonomy term: Parent term

5.4 Set Fields: Taxonomy term: Term ID, Taxonomy term: Term ID , Taxonomy term: Name, View: Include View (Include View)

5.5 Filter criteria (1): Taxonomy term: Vocabulary (= Colors)

5.6 Filter criteria (2): (Parent) Taxonomy term: Term

5.7 If you want you can also set "Exclude from display" for Term ID and a label of Include View

5.8 Set Path:/colors-tree

5.9 Set no results behavior: none

5.10 save

...and this should be it, finally.


I haven't tried the D6 or D7 version of this myself but I thought I would mention it in case it's what you're looking for: Views Tree Module - D7 progress

Edit: There is now a D7 version, checkout the module homepage Views Tree