Hi,
I’m redesigning a photography magazine and my current template for displaying the photographers projects is listed here.
The template search inside a folder the project.txt and the images. If a project doesn’t have images, kirby fails and give me some errors.
Not all the photographer send us the images, and sometimes I need to publish a video instead of a gallery of images. I’m using fotorama and there is an option to insert videos but I don’t know how to bypass the template to avoid errors.
Do you have any suggestions on how to fix this issue?
Well, yes, that is not surprising,if the subpage does not have an image, this code throws an error. You always have to check if an image exists before using a function that requires a certain type of object, in this case, the thumb() function wants an image object, and if it does not get it, it complains.
Without the else doesn’t show the video, but the video.jpg.
Anyway, I put a VideoUrl: field with url to the Vimeo video and then this in the projects code:
The first if-statement will always return true, no matter if there is a video.jpg or not, because $images will always be a collection object, even if the object does not contain any elements. But there is hope: