Hi,

I'm trying to get quite a complex view working and having some troubles. To explain:

On the drupal site we have a testimonial content type, which has pages of testimonials. We would like to be able to show certian testimonials on certian pages in a block.

So I've added an Entity Reference field to the basic page content type which lists all the testimonials in a select list when adding / editing a basic page. The list contains [nodeid] | [testimonial title].

I then have a View Block which then filters down to only testimonial content. What I am stuck on is how do I pluck out the selected testimonial from the current node / page field in the view block so i can filter to just the required testimonial?

When I create a relationship in views to the entity reference field it shows all the values entered on the basic pages field, not the current page's field...

Any suggestions would be great!

Comments

WorldFallz’s picture

You need to use a contextual filter with the 'provide default' and 'content id from url' options.

Caffeine Addict’s picture

worldfallz,

Using the contextual filter will limit the testimonals using the current node id, i need to match the current node's entity reference field to the testimonial node id? unless i'm missing something?

Caffeine Addict’s picture

WorldFallz,

You definitely know what your talking about! I tried again with contextual filters, getting the node id from the url of the current page, then used a relationship from the entity reference field to both the node id on the fields section and on the contextual filter section.

I'll document this and post a guide up in a bit! The thing which confused me was that the Views preview didn't show anything, but this does actually work...

Thanks again for putting me on the right track.

Kind regards,
Kevin

WorldFallz’s picture

sorry i wasn't clearer, but glad you got it! and the preview should work if you enter the nid of a node with testamonials into the filter textbox just before the preview button.

Caffeine Addict’s picture

Thanks again, just entered a node id of a page i know has the testimonial block showing and it shows the same block in the preview! would be good if views could pickup the current page behind the admin overlay.. Anyways i'll write up a use case / guide for this one when I get some spare time.

Lloyd’s picture

I'm about 90% up to speed on this but could use a little more direction. I have a similar issue.

Content Type A with entity reference field to Content Type B

I want to display a block view on Content Type B pages showing Content Type A fields only when the entity relationship exists between the two content types.

Lloyd’s picture

Figured it out. I reversed the content type I was filtering on.

cjamesrun’s picture

Have you put together a post on how you got this to work. I am having trouble with the reference or reverse reference.

hockey2112’s picture

@WorldFallz, I have two content types in question: Basic Page and Thumbnail Strip. Four of my basic pages require a specific thumbnail strip, and the rest of the basic pages should be allowed to display any of the thumbnail strips at random.

When I apply the contextual filter you mention here, the thumbnails are displayed properly on the four "different" basic pages, but the thumbnails are not displayed at all on all of the other basic pages (the ones that should display a random thumbnail strip). Can you direct me on what I would need to change to get the functionality I need?

PS, when I enter a node id in the contextual filters field in the view's admin screen, it does show the correct thumbnail strip. Then, when I enter a different nid or none at all, it does show a random thumbnail strip. So the full functionality seems to be working in the back-end, but still not on the front-end.

Thanks!