Search code examples
drupalnodes

Show content of referenced field in a block


I have 2 content types in Drupal: Articles and Newspapers. The Article type has a a reference field which points to the Newspapers. Each Article can only reference one Newspaper. So an article called Sunday reports belongs ta a newspaper The Times, article Monday reports belongs to The New Yorker. I created a view and inside that view a block. So when a user visit that article page it should display in a block to which newspaper it belongs.


Solution

  • In Views...

    1. Add a "contextual filter" of "content:nid".
    2. on this filter, set "WHEN THE FILTER VALUE IS NOT AVAILABLE" to "Provide default value",
    3. Set "Type" to "Content ID from URL",
    4. Then add a "Relationship" to your entity reference field
    5. Then in the output fields, add NID and set it to use the relationship.

    I am not sure what version of drupal you are using, but it should be basically the same for D7 - D9