Error on missing asset if thumbnail called

Thumbnails, Image Filters, Configuration, Previews, Properties, Custom Settings ...
Post Reply
donprosciutto
Posts: 6
Joined: Thu Jul 02, 2015 2:18 pm

Error on missing asset if thumbnail called

Post by donprosciutto » Sat Sep 05, 2015 11:33 pm

There is something that always bothered me about calling the getThumbnail method with pimcore objects.
Let's say I have a List of Object with an image, i could go foreach:

Code: Select all

echo $entry->getMyImage()->getThumbnail("myThumbnail")->getHTML();


But if the user creates an object, where he puts no asset in 'myImage' he'll get en error, because 'getThumbnail()' is called on NULL. (since getMyImage() will won't return an Image Asset). So i always have to check for this case in the view script:

Code: Select all

if($entry->getMyImage()){
    echo $entry->getMyImage()->getThumbnail("myThumbnail")->getHTML();
}


This is obviously no major issue, but it would be nice, if there was a better way to handle this. Maybe the getter for myImage could have a fallback asset for example: So that getMyImage() would return some placeholder image-asset (lie "no-image-available.png" or something) if the function gets called when myImage is not set. I think this would be much better than having the whole page break when this case happens.

Post Reply

Return to “Assets”



Who is online

Users browsing this forum: No registered users and 4 guests