Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Template.php

function Template::hasBlock

Returns whether a block exists or not in the current context of the template.

This method checks blocks defined in the current template or defined in "used" traits or defined in parent templates.

Parameters

string $name The block name:

array $context The context:

array $blocks The current set of blocks:

Return value

bool true if the block exists, false otherwise

File

vendor/twig/twig/src/Template.php, line 231

Class

Template
Default base class for compiled templates.

Namespace

Twig

Code

public function hasBlock($name, array $context, array $blocks = []) : bool {
    if (isset($blocks[$name])) {
        return $blocks[$name][0] instanceof self;
    }
    if (isset($this->blocks[$name])) {
        return true;
    }
    if ($parent = $this->getParent($context)) {
        return $parent->hasBlock($name, $context);
    }
    return false;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal