Conditional Image Display Using Formula Fields

You can use a Formula field to check whether an image exists in your image library before displaying it.
If the image is found, the formula returns formatted HTML to display it.
If it is not found, it returns nothing, ensuring your layout stays clean without unwanted gaps or placeholders.


Formula

C#
string strImg =@"(!IMG_Photo!)";
if(strImg == "" || strImg == null){
return "";
}else{
return "<table style='padding:0;border-collapse:collapse;border:none;'><td style='padding:5px;'>" + strImg + "</td></table>";
}

How It Works

  • (!IMG_Photo!) references an Image field that contains the image’s HTML code.

  • The formula checks whether the image field is empty or null:

    • If empty or null, it returns nothing.

    • If it contains an image, it wraps the image in a styled HTML table for consistent spacing.

IMPORTANT NOTE: in the example above we are referencing another field (an Image field) to get the name of the image. The image field contains HTML Attributes, such as border='0'. Make sure that this attribute does not contain double quotation marks "0" or it will break the formula.

image-20251111-230848.png