i am using the Builder Plugin and i want to use “$file->exists()” in the head of my section to prevent Kirby from throwing errors on missing files.
I saw the error as i placed to Images with the builder and deleted accidently one image.
Why dont i have access on “$file” within the Builder section template?
$file defined? Using
exists() doesn’t make sense (because the method already requires an existing object), just check for
$file = $page->files()->first();
// do something
If this doesn’t help, please post your code.
// CHECK HERE
if($data->picture() == '') return; ?>
<section class="row builder__image">
<img src="<?= $page->image($data->picture())->width(200)->url() ?>"
data-src="<?= $page->image($data->picture())->url() ?>"
<noscript><img src="<?= $page->image($data->picture())->url() ?>"></noscript>
<?php if($page->image($data->picture())->caption() != ''): ?>
<?= $page->image($data->picture())->caption() ?>
<?php endif; ?>
On the Line #1 i want to check if the file which is in §data->picture() is physically on the server.
Because i can delete the files which are used in the Builder.
Thats causing an error:
Call to a member function width() on null
if($image = $page->image($data->picture()):
// do stuff and use $image in the rest of the code so as not to repeat yourself
I did it with “exists” a bit around the corner.