Skip to content

Kirby 5.1.1

$blocks->hasType()

Checks if a given block type exists in the collection

$blocks->hasType(string $type): bool

Parameters

Name Type Default
$typerequired string no default value

Return type

bool

This method modifies the existing $blocks object it is applied to and returns it again.

Parent class

Kirby\Cms\Blocks

Examples

Useful if you want to include scripts etc. depending on block types.

$blocks = $page->blocks()->toBlocks();

if ($blocks->hasType('code') === true) {
  // include some scripts
}