When creating a signature, you may want to include an image such as a user photo or company logo only if it exists in your Image Library. This helps to keep your signature tidy by preventing empty spaces or broken image links from appearing when an image is missing.
This article explains how to use a Formula Field to check if an image exists before displaying it in your signature.
How It Works
The Formula Field checks whether an image is available in your Image Library.
-
If the image exists, the formula will display it using HTML.
-
If it does not exist, the formula will return nothing, ensuring your signature layout remains clean and professional.
Example Formula
Use the following example to test for the existence of an image and apply padding around it when displayed.
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>";
}
Explanation
-
Assign the Image Field
The variablestrImgis assigned the value of the image field (IMG_Photo).-
If the image exists, it will contain the HTML reference to the image.
-
If the image does not exist, it will be empty.
-
-
Check for the Image
Theifstatement checks whetherstrImgis empty ornull.-
If it is empty, the formula returns nothing.
-
If it contains an image, it returns HTML that displays the image neatly in a padded table.
-
-
HTML Output
The returned HTML uses a table with no borders and 5px of padding to ensure even spacing around the image.
Important Notes
-
Image Field Reference
The example references(!IMG_Photo!), which should correspond to an existing Image Field in your signature design.
ReplaceIMG_Photowith the name of your own image field if different. -
HTML Attributes
The image field may include HTML attributes such asborder='0'.
Avoid using double quotation marks (") within these attributes, as this can cause the formula to fail. Always use single quotation marks (') instead.