I am creating a map that contains spots, where the user can view some information by clicking them. I am using a route for the spots to get their content:
[
'pattern' => '/spots/(:any)',
'action' => function($uid) {
return snippet('spot', ['data' => page('spots/' . $uid)], true);
}
]
I am setting the last argument to snippet to true, to get the rendered HTML.
The snippet is rendered inside the same overlay box, that has its content replaced on every spot visit.
The snippet’s code:
<?php
$image = $data->content()->image();
?>
<div>
<header>
<img src="<?= e($image->isNotEmpty(), $image->toFile()->url()) ?>" alt="">
<h1><?= $data->title() ?></h1>
</header>
<div class="content">
<?= $data->content()->content()->kirbytext() ?>
</div>
</div>
The problem is that for every spot visit, the $data passed to the snippet seem to be concatenated. If after visiting some spots, I do a dump($image) inside the snippet, I am getting something like that:
Kirby\Cms\Field Object
(
[image] => image1.jpg
)
Kirby\Cms\Field Object
(
[image] => image2.jpg
)
Kirby\Cms\Field Object
(
[image] => image3.jpg
)
This does not affect the spot’s rendering, but if for example an image field is empty, I get an 500 server error.