If the page does not exist, we set the $items variable to null, i.e. a variable without a value. That’s nowhere in the docs, but general PHP. Could have set this to false
as well.
It is basically the same as
<?php
$items = null; // or false
if ($spendenPage = page('spenden') {
$items = $spendenPage->spenden()->toStructure();
}
// rest as before
Or we can set $items
to a new empty Structure collection (then we need only one condition in our if statement):
<?php $items = ($spendenPage = page('spenden')) ? $spendenPage->spenden()->toStructure() : new Structure(); ?>
<?php if ($items->isNotEmpty()) : ?>
<?php foreach ($items as $item) : ?>
<?= $item->betrag() ?>
<?php endforeach ?>
<?php endif ?>