Skip to content

Kirby 4.1.2

$blocks->hasType()

Checks if a given block type exists in the collection

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

Parameters

Name Type Default
$type * string

Return type

bool

Parent class

Kirby\Cms\Blocks

Example

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

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

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