Blog IT

Drupal offers a mechanism in the backoffice to control the display of blocks, but it is sometimes necessary to set up a little more complex logic.

Here we are going to hide the "id_block" block from the "header" region when we are on an "article" type node via the HOOK_preprocess_page hook:

<?php
function blog_preprocess_page(&$vars)
{
    if (($node = \Drupal::routeMatch()->getParameter('node'))
        && $node->bundle() === 'article') {
        if (isset($vars['page']['header']['my_block'])) {
            unset($vars['page']['header']['my_block']);
        }
    }
}
?>