Hi,
I have a strange behaviour on my page. I have a onepager where I publish all sections as own page with blocks. And for two pages I need a seperation for this I change the page-collection in the controller. But on the two singlepages I got the error
Call to a member function toBlocks() on null
inside the foreach foreach($section->contentblocks()->toBlocks() as $block):
.
If I dump the $section I have a regular JSON in my field so there should parse it with toBlocks() without no problems like on the onepager where I have no problems.
dump of $section:
controller:
return function ($page, $pages, $site, $kirby) {
$shared = $kirby->controller('site', compact('page', 'pages', 'site', 'kirby'));
if($page->slug() == 'impressum'):
$collection = $pages->listed()->find('impressum');
elseif($page->slug() == 'datenschutzbestimmungen'):
$collection = $pages->listed()->find('datenschutzbestimmungen');
else:
$collection = $pages->listed()->filterBy('slug', '*=', 'sektion');
endif;
if ($site->logo()->isNotEmpty()) :
$headerimage = $site->logo()->toFile();
endif;
if ($site->footerlogo()->isNotEmpty()) :
$footerlogo = $site->footerlogo()->toFile();
endif;
$intendedTemplate = $page->intendedTemplate();
$maintenance = $site->maintenance()->bool();
return ['shared' => $shared, 'collection' => $collection, 'headerimage' => $headerimage, 'footerlogo' => $footerlogo, 'intendedTemplate' => $intendedTemplate, 'maintenance' => $maintenance, ];
};
Template:
<?php
$n = 0;
// $maintenance = $page->intendedTemplate() == 'maintenance';
$maintenance = $site->maintenance()->bool();
if (!$kirby->user() AND $maintenance) :
go('/wartungsmodus');
endif;
?>
<?php snippet('site/htmlheader'); ?>
<main class="main container-fluid">
<?php foreach($collection as $key => $section): ?>
<section class="<?php echo $section->slug() ?>">
<?php foreach($section->contentblocks()->toBlocks() as $block):
$blockType = $block->type();
if($blockType == 'titletext') $n++;
?>
<?php snippet('blocks/' . $blockType, [
'block' => $block,
'count' => $n
]) ?>
<?php endforeach; ?>
</section>
<?php endforeach ?>
</main>
<?php snippet('site/footer') ?>
markdown Block:
<div class="blocks <?php echo $block->type() ?> <?php echo $block->id() ?> border-<?php echo $block->textborder() ?>" id="<?php echo $block->id() ?>" style="color: <?php echo $block->palette() ?>">
<?php echo $block->text(); ?>
</div>
Hopefull I have not missed something