07.05.2026 | Dominik Wille

Exclude already-displayed entities from a view

Use the views_exclude_previous module. See below or open the module documentation for further information.

Issue:

A page contains multiple Views blocks showing entities of the same type – for example teasers, lists, or cards. Without coordination between them, the same entity can appear in more than one block on the same page.

Solution:

Install and enable the module using your favoured method. 

It provides a contextual filter that tracks which entities have already been rendered on the current page. Adding this filter to subsequent Views blocks ensures each entity appears only once, regardless of how many Views are present on the page.

Weitere DevBits

24.02.2026 | Lothar Ferreira Neumann

Hide a view if it yields no results

The Option in the view

Click here to enable the following option:

The checkbox to hide the view when its empty.

 

Sitebuilding
views
12.02.2026 | Pascal Crott

Dynamically remove entity_reference value from views exposed filter via flag

my_module.module
<?php

use Drupal\Component\Utility\Html;
use Drupal\Core\Form\FormStateInterface;


/**
 * Implements hook_form_FORM_ID_alter() for 'views_exposed_form'.
 */
function hook_form_views_exposed_form_alter(&$form, FormStateInterface $form_state) {
  // Configure the values to your needs.
  $view_name = 'my_view';
  $display_name = 'my_display';
  $entity_type_id = 'taxonomy_term';
  $reference_field = 'field_category';
  // The field on the referenced entity.
  $flag_on_reference_field = 'field_hide_on_exposed_form';

  if ($form['#id'] == Html::getId("views-exposed-form-{$view_name}-{$display_name}")) {
    $entity_storage = \Drupal::entityTypeManager()->getStorage($entity_type_id);
    $options = &$form[$reference_field]['#options'];
    foreach ($entity_storage->loadMultiple(array_keys($options)) as $id => $entity) {
      if ($entity->hasField($flag_on_reference_field) && !$entity->{$flag_on_reference_field}->isEmpty()) {
        unset($options[$id]);
      }
    }
  }
}

module
views
exposed filters
copy-paste
potential module