0

I have a homepage content type which has a featured_article field, an entity reference field that allows the editor to choose a single node from the Article nodes. That node is displayed as Featured article on the homepage.

Together the featured article on the homepage, I'm rendering a view (block) that displays the latest articles. I would like to avoid the node selected as featured article doesn't appear in the view. How can I achieve this?

This is my first Drupal project (coming from Craft and ExpressionEngine), and I'm struggling to figure out how to properly configure the view. I expect that I need to use a contextual filter together with a relationship, but I haven't had any luck. I could probably work in a conditional in the Twig template, but I'd prefer to keep the logic in the view if at all possible.

1

Welcome to Drupal Answers :)

You are right, you can do that with the help of a Relationship and a Contextual filter, but details are important.

In your Latest articles Views add the Relationship named something like Content referenced from field_myERfield for your featured article field. Be careful about the wording there because there are two Relationships available for the same field, you want the "backwards" one. Don't require the Relationship, otherwise you'll get no results if your home page isn't an article type.

Add the Contextual ID filter and set it to use the Relationship you've just added. Provide default value and choose Content ID from URL. Under Validation choose Content and Article, and other options that make sense in your case.

Then under More choose Exclude. That is how you exclude the currently featured article(s) from the latest articles list.

If you don't choose Exclude you'll only see the featured article in the results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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