0

Is it possible to display multiple content types within a view that may or may not have a related secondary content type?

I have two content types (A - which contains a title and body field, and B - which contains a title and body field). In this view, content type A will always exist - and I would like to have any related B content types display underneath the appropriate object. It is possible that no content B types will exist for that title, so if that's the case it can move on and display the next content A type info:

(A) Title = New York, body = "Something"
(A) Title = Ohio, body = "Something"
     (B) Title = Ohio, body = "An interesting tidbit about Ohio"
(A) Title = Virginia, body = "Something"
...etc...

Any idea how I may go about accomplishing this? I have heard about a References module to explore, but it seems like that would only pull data where that relationship exists, right? And that in my above example, although I would be anticipating three states in my view, references would only show me the Ohio one because that's the only one that also contains a content B type.

Is that correct? Or is my understanding incorrect?

  • How do you relate Type B to Type A? Do you use a refernce field? What is the cardinality of the reference (0-1, 0-many)? – Triskelion Jul 23 '13 at 19:53
  • That's part of my question, I guess. Right now, nothing is set up. Content B would have a 0-1 relationship to Content A. Any idea how I would set up a reference like that? – R Brennan Jul 23 '13 at 19:56
1

Install the Entity Reference module, and create an entity reference field on your Content Type B. Configure the field to reference Target Type Content and Target bundle Type A. Lets call the field ref_to_a.

Set up a view of Content Type A as a table of fields. Add the Title and Body fields. Then under Advanced add a Relationship. Use Entity Reference: Referencing Entity and choose Content referencing Content from field_ref_to_a Do not set the relationship as required, as you do not want to exclude the Type A records which do not have a Type B referencing them.

Now add a Content:Body field to your view, and configure it to use the relationship you have just created.

This should give you a view which will look like:

New York    Something
Ohio        Something   Interesting tidbit
Virginia    Something

Adjust your formatting as required, and good luck.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.