How to create a view which would list related content for current article?

by Sébastien Gicquel   Last Updated December 19, 2017 15:07 PM

I try to create a view which would list related content (some articles) to a content type article.

Here is what i’ve done. I’ve created a field "Entity reference" in the content types "Article". It works. I can see in database the related article ID .

enter image description here

Then, I create a view with a block. It works, i can see all articles listed in that view (which is visible on each article).

Here is my issue. I need to display only articles related to the current article. So, in contextual filter, i have tried with Content: ID and also tried with advanced/Relationships but without success. I don’t see my related articles.

enter image description here

enter image description here

enter image description here

How can I do ?

I’ve also tried a different way (create a twig) and even if it works, it is not the best solution i think



Answers 1


Ignore the fields.

Set the view to show "Content" and give it a view mode, for instance, create a view mode called "Related Content" for nodes. In the field display for that view mode, only set the "Related Articles" field to be visible. Set its field formatter to "Rendered Entity", and create a view mode for that content type and theme it.

Now the View will pull the node, render it, and in turn render the nodes that are being referenced in a view mode.

Kevin
Kevin
December 19, 2017 15:05 PM

Related Questions