I have a content type of Company, which can have multiple Images. In the company node, i want to display a slideshow of the images which belong to the company.

For some reasons, instead of storing the images in a field of Company, i created another content type of Image, which references the Company through an Entity Reference field type.

So now i have a view of Images which i want to filter using the reference field. I tried adding an Contextual Filter, but the filter cannot find the related images, which i think because the url is transformed. For example if the company has the name The Company, the path becomes /company/the-company (i am using automatic alias).

How can i filter the images correctly in the company page? Thanks.


1 Answer 1


To get your NID back (after it has been aliased) one of the solutions here is for you:

Drupal 7 Contextual Filter on URL Alias

But first I'd make sure your view is set up correctly with a contextual filter that has a relationship to the entity reference field ...

On your "view" click "Advanced". Click the "Add" button to the right of Relationships.

Find the "Entity Reference: Referenced Entity" relationship and check the box. Click "Apply". On the next screen, click "Apply" right away unless you want to change the identifier or make the relationship required.

enter image description here

Once you are back to your view's 'advanced options' Click the "Add" button to the right of Contextual filter and select "Content: Nid".

enter image description here

Under "Relationship", ensure that the entity reference relationship you added previously is selected. Next, select "Provide default value" and then set the type to "Content ID from URL". Click "Apply".

enter image description here

Stolen from here: https://www.drupal.org/node/1841004

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