Views Tree allows for the rendering of hierarchical relationships between entities or users as displayed in a View. The module simply adds a display format for Views titled 'Views Tree (adjacency model)'.

Views Tree with Taxonomy Terms

Creating Taxonomy Terms

Create some Taxonomy terms with parent/child (hierarchical) relationships.

Creating the View

First, create a new term view using the fields row style / unformatted list of fields (it is important that the tree style not be chosen now). Then:

  1. Add relationship for taxonomy term: parent term
  2. Add field term id (do not use relationship) and exclude it from display
  3. Add field term id with relationship, exclude from display
  4. Add any fields you want to display, like term name, term description, etc...
  5. Change style / format plugin to Tree (Adjacency model)
  6. Set Main field to Term ID
  7. Set Parent field to Term ID with parent relationship

(These instructions are taken from #1424414-6: How to configure for D7 Profiles/Taxonomy terms.)

Views Tree with Book module (to create book table of content - TOC)

Creating Book pages

Create a book and add some pages with parent/child (hierarchical) relationships.
Optionally, you can use the Outline Designer module to organize your book pages.

Creating the View

First, create a new view of your book content using the fields row style / unformatted list of fields (it is important that the tree style not be chosen now). No need for sorting but you can choose to output as a block.

Then:

  1. Add relationship for Book: Parent
  2. Add field Node ID (do not use relationship) and exclude it from display
  3. Add field Node ID with relationship, exclude from display
  4. Add title field (do not use relationship)
  5. Change style / format plugin to Tree (Adjacency model)
  6. Set Main field to Node ID
  7. Set Parent field to Node ID with parent relationship

Be aware that tree structure is not displayed in view preview.

Finally, you can set the block to be displayed on sidebar of every book content type so you have a nice hierarchical table of content where, not bad at all, current page is highlighted.

(These instructions are taken from above example using taxonomy terms.)

Showing just one book

The instructions above will show all books. You can limit the view to show
just one book, if you want.

  1. Add a relationship from nodes to their book's top-level node
    • Click the Add relationship button (under Advanced settings)
    • Add the Top level book relationship:

      Add relationship
    • You don't have to change the relationship's default configuration.
  2. Add a criterion using the relationship
    • Click the Add criteria button.
    • Choose the Title field from the Content category:

      Add criterion
    • Configure the criterion to use your new relationship, and
      the title of the book you want to show. That will be the
      title of the book's root node.

      Configure relationship

Views Tree with Relation Module

Setting up references

Using the Relation module, add some entity items, and set them to reference each other.

Creating the View

  1. Create your view and add your relationships to the view (you will need to add a relationship [view relationship] from your bottom level node to the relation [built using the relation module] AND another relationship [view relationship] from the relation [relation module] to the node [being the next node on the hierarchy].
  2. Add a node id for the base level node (don't use a relationship).
  3. Add a node id for the next node up in the hierarchy (use a relationship for this one - the relation set up in the relation module) - call this one pnid (or parent node id).
  4. Hide the node ids from display.
  5. Change the display to Views Tree (Adjacency model) and set the Main field to nid and the Parent field to pnid.

(These instructions are taken from #1911510-1: Support for the Relation Module.)

Views Tree with References Module

Setting up a Content Type

  1. Using the References module, add a node/user reference field to one of your entity types.
  2. Make some content that references other content.

Creating the View

  1. Create a new view with a display using Views Tree (Adjacency model).
  2. Configure the view:
    1. Add a relationship:
    2. The relationship field you have on your entity (in my case, Parent Page).
    3. Add the following fields:
    4. Node: title
    5. Node: nid (this will be the unique record for the row).
    6. Node: nid (set this second one to use the relationship you defined earlier. It’s also a good idea to set an administrative name under ‘More’ distinguish it from the other ‘Node: nid’.
    7. (Set "nid" fields to be Excluded from display).
    8. Set up settings for the Views Tree format:
    9. Main field == nid.
    10. Parent field == Parent/reference nid.
  3. Profit!

Views Tree with Entity Reference Module

Setting up references

Using the Entity Reference module, add some entity items, and set them to reference each other.

Creating the View

  1. Create a new View using the Fields row style and configure the Filter criteria i.e. Content Type.
  2. Add the desirable fields i.e. Node ID, Node Title, and the Node Reference field and configure their display.
  3. Set the View's format to "Tree (Adjacency model)" and set linking fields titled Main and Parent accordingly.
    In this example the Main field would be the Node Id and the Parent field the Node Reference field.
    Generally, you will want to link from a nodereference field to the nid on the same node type. That is, the nodereference field is used as a pointer to the "parent" node.
  4. Save and enjoy.

Note: When using the preview in Views (D7) the result seems like a flat list with no hierarchy but that is a CSS issue of the admin theme. If you set the list type to an 'ordered' list in Format Settings the preview works fine.

TODO: Add documentation for this process—see #1719206: Test with Entity Reference, add to documentation/readme/project page.

Views Tree with Organic Groups

Creating the View

  1. Create a new View using the Fields row style and configure the Filter criteria i.e. Organic Group Content Type(s).
  2. Create relationship: OG membership: OG membership from Node
  3. Create new relationship: OG membership: Group Node from OG membership using OG membership from Node
  4. Create a field: Content: Nid (Group Nid)
  5. Create a new field: Content: Nid (Parent Nid) using the relationship Group Node from OG membership
  6. Set the View's format to "Tree (Adjacency model)"
  7. Update the views format settings:
    • Main field: Group Nid
    • Parent field: Parent Nid
AttachmentSize
Add relationship22.75 KB
Choose criterion22.43 KB
Configure relationship28.64 KB

Comments

TravisJohnston’s picture

with D6, the relationship field isn't available for the second nid, nid in general... looks like this is the only module available that can do what I want but it seems that its made for d7? or is it need views 3?

*EDIT - This works fine for some cases, for instance I used Views Tree to create a task list with parent tasks and it worked great, though it i try to make an Organizational Chart for users, the nid does not have the field... so looking into it.

Thank you kindly,

Travis Johnston

Creo Coding - Let's Start Our Journey!
Owner and Web Developer
http://www.creocoding.com

Facebook - Facebook.com/CreoCoding
LinkedIn - http://lnkd.in/rQrdS7

petre.tudor’s picture

Hi,

I want to ask what point 1. from "Views Tree with Taxonomy Terms" means? Where to 'Add relationship'?

------
Edit: I found it in the Advanced section in edit view screen
------

Thanks for your great work!

Petre

uzuri’s picture

I'm trying to set up a views tree using a structured Taxonomy, but I've run into a wall with step 2: "Add field term id (do not use relationship) and exclude it from display"

So far as I can see, I can't add a field term id without a relationship. I'm also not convinced that I'm doing step 1 correctly (am I supposed to be adding a "Content: Taxonomy terms on node " or something else? There's no choice for just "taxonomy term" or "taxonomy term: parent term").

loopy1492’s picture

I'm in the same boat. Even though I added the relationship with Require Relationship turned off, it shows as being used with the relationship. What's more, I had to add a contextual filter for the Taxonomy in order to use it as a relationship. I don't know if that has anything to do with it.

nlambert’s picture

I've tried with entityreference module. The procedure for the references module seems to work perfectly for the entityreference module. Maybe this doc could simply be updated to :

Views Tree with References Module => Views Tree with References Module & Entity Reference module.

Just a thought.

digitgopher’s picture

Same here. I'm using entityreference, and had to use the References module instruction instead of the entityreference instruction for it to work.

arigalt’s picture

Hi, congrats for the great module,
I have try to do it with the user reference, and after I follow the above instructions work nice, but still can't make that the tree start from an specific uid.

For example I have something like this,

if I'm bob login in i will see this

Bob
--- Mary
--- --- Jane
--- --- --- tim
--- --- --- John

if i'm Jane login in I will see this

Jane
--- tim
--- John

What is missing or how can I make it work correctly, thks for your time.

mr4711’s picture

All entries of the taxonomy are alphabetical sortet, there is not any tree. Any idea what went wrong? This changes when I use the weight modul and take this as a sort criteria. Is it necessary?
Michael

Dimetry’s picture

Views Preview does not show the tree layout but normal page display does output as a tree.

niallmurphy-ie’s picture

I can't seem to make this work with Organic Groups.. Anyone else have success?

Thanks

markdc’s picture

Also need help getting this to work with OG.