0

I have cloned the OOTB displaytemplate "Item_PictureOnTop.html". I would like to show a default picture if the picture not found on the item. Is that possible with custom css?

example here of current situation

1

In your copy of Item_PictureOnTop.html you have to add some additional javascript logic to check if there is an image, and if not, insert something else.

An example could be

<!--#_

    // ...

    var noPictureFoundImgUrl = "url to image for no picture found"
    var imageUrl = null;

    if ($isEmptyString(ctx.CurrentItem.ImageUrlColumn))
    {
        imageUrl = noPictureFoundImgUrl;
    }
    else
    {
        imageUrl = ctx.CurrentItem.ImageUrlColumn;
    }

    // then insert the 'imageUrl' variable in the markup

    // ...

_#-->
0

Daniels solution checks for empty url, not if an image was not loaded.

I don't think you can do it with CSS since onload of an image is a JavaScript event.

There is no notloaded event

It requires some (minor) changes to the DisplayTemplate to do the opposite:

Reveal loaded images

  • add an onload event to the image
  • display your default IMG in a DIV with absolute position on top of the image
  • in the onload that fires (for every image) remove the default IMG that is covering this image

That way you can also add fancy CSS animations

Als je er niet uitkomt, kun je me inhuren...

CSS only (by Jussi Palo)

You can achieve something with CSS only if you add:

.cbs-pictureOnTopImageContainer{
    background-image:url('/mydefaultimage.jpg');
    background-size:cover;
}

But the broken image indicator will be displayed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.