I’m updating my site from Kirby 2 to 3, and I’ve run into a problem. I have several image fields for main page image, page background and so on. They all work in that I can choose a page image and the filename gets added to the plaintext file for the page.
Thing is, when I edit a page Kirby adds a '- ’ (a dash and a space) before the filename. There didn’t used to be, and it’s breaking my templates. I’ve tried ‘$page->bgimage()’ and ‘$page->bgimage()->filename()’ (bgimage is one of the fieldnames) and nothing gets returned. If I remove the hyphen manually, it all works again.
What am I missing? Is that hyphen supposed to be there, and why? Also, why does it break the above functions?
Edit: in my blueprint I have this kind of set up for each image:
Thanks for replying! I was using that before, and kept getting PHP errors. Right now if I try that on my main template it returns the filename with the hyphen “- img_0635.jpg” and on my header snippet where I put in a background image I get a fatal-looking PHP error. Screenshot from debug:
Don’t know what’s happening on your side, but I just tested this in a project I’m converting to Kirby 3 and it works as expected.
Are you calling this code in a loop where not all images have the field filled in?
I don’t get enough context from your code snippet, but the way you coded that is not recommended anyway, because you should never ever call a class method (like url() in this case), without making sure you got an object to call it on. So either use an if statement like above or a ternary operator: