Sunday, September 9, 2018

Show a Default Image or Text on an Item Page if the Item has no Display Thumbnail Image


A default image or text can be displayed to replace the Item Thumbnail image on the webstore if it is not available.

This can be achieved by using custom script:

1. Customize an item list cell template by going to Setup > Site Builder > Item/Category templates.

2. Enter either of the sample code below:

a. To show a default image:

<script language="JavaScript">
var customImage = "<%=getCurrentAttribute('item','storedisplaythumbnailhtml')%>";
if (customImage == "")
{
document.write ("<A href='<%=getCurrentAttribute('item','storeurl')%>'><img src='/site/images/image.gif'></a>")
}
</script> 

b. To show a default text:

<script language="JavaScript">
var customImage = "<%=getCurrentAttribute('item','storedisplaythumbnailhtml')%>";
if (customImage == "")
{
document.write ("<div style='width:100px; height:100px; border-style:dashed; border-color:#FF00FF; border-width:2px;' align=center><br><br><br>Image Not Available!</div>")

}
</script>  

3. Apply this custom item list cell template to a custom Item List Layout.

4. Apply the custom Item List Layout to the custom Theme or category record.



No comments:

Post a Comment