Skip to content

Kirby 3.9.8

$blocks->findBy()

Find a single element by an attribute and its value

$blocks->findBy(string $attribute, mixed $value): mixed|null

Parameters

Name Type Default
$attribute * string
$value * mixed

Return type

mixed|null

Parent class

Kirby\Cms\Blocks inherited from Kirby\Cms\Collection

Example

Find blocks by attribute, e.g. type:

$textBlock = $page->text()->toBlocks()->findBy('type', 'image');

Returns the first block of type image if it exists.