I just had a website running and my client uploaded some projects. After some time, an error occurred. In my test version on my Mac everything worked out just fine so I actually don’t know where to start.
The pages shows 5 different categories of his projects. I did the categorization with checkboxes and on the frontend with filterBy. For example for all city projects I do: <?php foreach($projects->filterBy('categories', 'city') as $city): ?>
It stopped working somehow. Here is the complete code:
Without any further information, I can only guess and think the error is likely caused because you call the url() method without prior checking if you have an corresponding object, in this case a file object. Never call a class method without checking if you actually have an object!
Depending on your use case, you might want to put the if-statement around the complete div or put something else instead of the image within the anker element, so as not to end up with an empty element in case there is no image.
Edit: In your topic title, you mention the isNotEmpty() method, but I can’t see it being used in your code?
As I tried to say above, whenever you deal with objects and their methods (pages, fields, files etc.), always use an if-statement (or equivalent) to check if you have an object first, otherwise you are doomed to run into errors over and over again.