Hi all,
I’m using the page builder from @timoetting, following the steps to get images in the backend and front from a snippet. All worked properly until i erased an image to replace it with another.
I thought the isNotEmpty would prevent an error if the picture field was empty.
I’m a bit clueless on what I’m doing wrong, I’m probably mistaking somewhere.
Thx in advance for the help.
Théo G.
<?php if ($data->picture()->isNotEmpty()): ?>
<img src="<?= $page->image( $data->picture() )->url() ?>">
<?php endif ?>
Whoops\Exception\ErrorException thrown with message "Call to a member function url() on null"
Is the field really empty? If you remove an image, the field value is not automatically deleted. In any case, it is recommended to check if an (image) object exists before calling a method on it:
The Problem is, that $page->image($data->picture()) doesn’t return an image object, because the image was deleted. And so the url() method can’t be used afterwards.
Super great ! Thanks a lot @texnixe verifiying if there was an image corrected my issue and @flokosiol for the extra information, now i understand a bit more how this thing works .
Kirby community sure is a quick one.