First time using Kirby and I am trying to do an optional field for the user. I’ve added the image to my control panel however it’s not getting the correct path.
getting this error in devtools:
GET http://localhost/whats-on/-%20hotel.png 404 (Not Found)
whats-on/ is the directory of the pages parent
should be /whats-on/currentpage/hotel.png
the variable “$page” does not lead to the page you need or want.
It should contain “/whats-on/currentpage”, but it shows “/whats-on”.
Temporarily add in front of the “if” line to check that:
<?php dump($page); ?>
or
<?php dump($page->url()); ?>
Tip:
Have you written “if ($page = ...)” instead of “if ($page == ...)” somewhere in the code before the code snippet (one equal sign instead of two)?
the content of the variable “$page->circleImg()” obviously starts with “- ” (shows “-%20”)
Try to change “$page->circleImg()” to “$page->circleImg()->toFile()”, if it contains only ONE file. Else use “toFiles()” in an “foreach” block.
Supplementary:
Try to change “->isNotEmpty()” to “->exists()” in the “if” line!
Ah working now, thank you both!
texnixe I originally was going to do the alt tag stored in the page, but out of curiousity how would I go about generating that with the image’s metadata?
You have to assign a file blueprint to the uploaded files. In a file blueprint, you can define the fields you want to have in your file metadata. For example, an image.yml could have a field for the alt attribute and maybe fields for the photographer etc. Then with the data filled in, you can call $image->alt() or whatever you call that field etc.