Views - context filter by nid I have created a view, which basically queries files of type image. That view creates a block, which associated with a certain content type. So the block is displayed whenever one of the nodes of that type is displayed, exactly what I would like to have.

Each of the files displayed has an entity reference field, which contains multiple references to that content type. So that is a one to many relationship, where one image can have multiple nodes of that type associated.

Is it possible within the views ui, to set a contextual filter that it sorts out each file, whose entity reference field (to that content type) contains the current node id?

In pseudo SQL the statement should look like:

SELECT filename, path, node_refs FROM files WHERE node_refs contains &lt;current node id&gt;;

Thanks in Ahead!
Add a relationship as Entity Reference: Referencing entity
Name it with the name of your content type for instance (easier to read in the view settings)
Check the Require this relationship option
Add a contextual filter with Content: Nid


Here comes the trick!


Choose Provide default value in the WHEN THE FILTER VALUE IS NOT IN THE URL fieldset
Type should be Content ID from URL


This will make Drupal fetch the context from the current URL where your block is displayed and loop through the files referenced by the current node.

TA-DAAA :-)