Conditionally Display Images from the Image Library

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.

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>";
}

Explanation

  1. Assign the Image Field
    The variable strImg is 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.

  2. Check for the Image
    The if statement checks whether strImg is empty or null.

    • 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.

  3. 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.
    Replace IMG_Photo with the name of your own image field if different.

  • HTML Attributes
    The image field may include HTML attributes such as border='0'.
    Avoid using double quotation marks (") within these attributes, as this can cause the formula to fail. Always use single quotation marks (') instead.