What I'm trying trying to do sounds fairly simple, but I can't get my head around it.

I'm having 2 taxonomy vocabularies: machinery and batteries (both created with NAT), and 2 content types which are named the same.

Both the content types provide the ability to check related items (a term reference field). For the machinery node the user can check which batteries are suitable, and for the battery node the user can check which machines use this battery.

Basicly what I'm trying to is: if you're on a page about a specific machine, it should show the batteries that are related to it, be it as teasers (or fields) in a block. And vice versa: when you're on a page about a specific battery, it would show all the machines in which it fits.

I've been boggling around with relationships and contextual filters, but it just wouldn't work out so far (spent a couple of hours here). Does anyone have an idea how to sort this out please?

Comments

knalstaaf’s picture

Project: Views (for Drupal 7) » NAT-ng (Node Auto Term)
Version: 7.x-3.7 » 7.x-1.0-unstable1
Issue summary: View changes
knalstaaf’s picture

Project: NAT-ng (Node Auto Term) » Node Auto Term [NAT]
Version: 7.x-1.0-unstable1 » 7.x-1.x-dev
knalstaaf’s picture

My solution

Create
2 content types, both correctly configured with NAT:

  • Machinery
  • Battery

2 vocabularies, both will be filled along the way with terms generated by NAT:

  • Machines
  • Batteries

Remark the difference in names, just to keep things clear in this explanation (so you don't mix up).

  1. Add a "Term reference" field in both the content types. In het "Machinery" content type this field will refer to the "Batteries" vocabulary, and vice versa: the "Battery" content type has a term reference field that's linked to the "Machines" vocabulary.
  2. Create the necessary nodes with both the Machinery and the Battery content type - which will generate terms in both the Machines and Batteries vocabulary.
  3. Once this is done, check the right terms in each node: what batteries are related to this machine (for the Machinery nodes), and vice versa: in what machines does this battery fit (in the Battery nodes).

Once this is done, create a View and create a block in it. The block in this example will display related machines, being displayed on the page of a battery.

  1. Set the format to whatever you like (HTML-list, unformatted, grid, ...). I'm using fields in this example (not content, but it should work as well).
  2. Add the fields you'd like to show (Title, Image, ...)
  3. Add the following filter: Content: type (=Machinery)
  4. Now add 2 relationships:
    • NAT: Nid (Identifier: "NAT node")
    • Content: Taxonomy terms on node
      • Relationship: "NAT node"
      • Vocabularies: "Machines"
      • Identifier: "term"
  5. Add a contextual filter:
    • File Usage: Entity ID
      • Relationship: "NAT node"
      • When the filter is not available: provide default value (Content ID from URL)
  6. Finally go to the Query settings of the View and check "Distinct" (to avoid duplicates).

Et voila, the first block is ready to go.

For the second block that will show associated batteries on a Machinery page, duplicate the block we've just created and modify the proper settings accordingly (content type filter, vocabulary in taxonomy terms on node).

You should be good to go - it works in both ways now.

I've add some screenshots in case they may be useful (with other names though than in this example, so don't get confused).

(Maybe EVA does something similar, both the method above works in both directions)

knalstaaf’s picture

Status: Active » Closed (fixed)
knalstaaf’s picture

knalstaaf’s picture

Addendum:

There's possibly an easier way with the References module. In that case it wouldn't even require NAT, but just a View with contextual filter based on the Reference field:

  1. Provide a node reference field to the content type you want to display.
  2. Use that field as a contextual filter in the View (default value: Content ID from url).
  3. Add this view display as a block to the content. The node in which it's being displayed will be seen as a parent of the nodes that reference to it for instance.

Can't remember if it would meet the requirements of the starting post, but it may be close.

mrpauldriver’s picture

Thank you for this, saved my day,

After reading that a generated term can not be attached to the parent NAT node I was beginning to think that creating a view of related content based on a node title terms was not possible - https://www.drupal.org/node/155411