Finding the existance of an image in CMS

We need to use a default image when one is not available. Each image has meta data associtated with it that ties it to the page so I am looking for a way to query the CMS using that data to see if it exists. If not, use the default image when producing the page.

in your location scheme, do something like this:

if($sys.item.getProperty(‘rx:image’).isNull()) { ‘http://default/image.jpg’; } else { …fill this in… }

it might not be “isNull” but “isEmpty()” or something else like that, but you can certainly inspect for a value here.

It can be tricky testing for the existence of a file property as the property returns a stream object. A better way for a file or image is to check the file size which should be populated by the sys_FileInfo extension automatically added as a dependency of the sys_File control. any file field with name xxx will have a xxx_size field populated. If the file does not exist or the file is empty this will be 0. I have not tested this but should work like below.

if($sys.item.getProperty(‘rx:image_size’).Integer > 0) { …fill this in… } else { ‘http://default/image.jpg’; }