Drupal 8 vs me

Drupal 8 vs me

Monday, February 27, 2017

Drupal 8; Exclude the current node from a View



Okay, this is rather simple once I found out how.

PS most documentation out there is for Drupal 7 and mentions NID, now as a newbie I could not for the life of me find NID in Drupal 8.


"Add" on "Contextual Filter".
Search for "ID".
Choose "ID: Content" (ID under TITLE,Content under CATEGORY, DESCRIPTION is blank).
Under "WHEN THE FILTER VALUE IS NOT AVAILABLE".
Select "Provide default value".
Select "Content ID from URL"
Scroll to bottom of the current Contextual Filter window and under "MORE" tick the box that says "Exclude".
And "Apply".
Window will close and then "SAVE" the View.
You will need to test on various page as "Preview" will not show results.

Note: as a general rule this Contextual Filter I have just created needs to be first in line under "Contextual Filters". Down arrow were to see Add "Contextual Filter", click on rearrange and then move "Content: ID to top".

Now for the next View and I am having to get some help on.

2 comments:

  1. Will this also work for view blocks?

    ReplyDelete
  2. I am embedding a as below:
    $relatedArticles = views_embed_view('blogs', 'block_1');
    $variables['related_articles'] = $relatedArticles;

    in hook preprocess node

    ReplyDelete