Introduction
While you can insert static images into your templates, you can also insert dynamic images. For example, you may want to include an image of your product on a Product Specifications PDF. Rather than cloning the same template many times (once for each unique image), you would rather have just one template that dynamically includes the right image. You can accomplish this in several ways.
Option 1: Use a rich text field
This is perhaps the easiest method. You first upload your image into a standard Salesforce rich text field on your record detail page. Then, open the template in which you want to add the image, click on the Template Editor button, click on the Insert Field button, select the rich text field, click on the Contains Rich Text checkbox, and finally click on the Insert button. Your documents will now render the rich text content for that record wherever you placed this field.
Option 2: Use a standard text field that contains the entire image markup
You can also use a standard Salesforce text field whose value contains the complete image element tag that you want to include. Each record would potentially contain a different link that corresponds to the applicable image.
For example, set the value of a ProductImage__c field on a Product record to:
PRODUCT IMAGE:<br><img src=”/host/Product123Image.png” />
Then, using the S-Docs template editor, click on the Insert Field button, select the field, and then be sure to click on the Contains Rich Text checkbox.
This is a simple approach but has limited usage. It is useful for images such as representative signatures, where they are centrally controlled by an administrator, they do not change frequently, and the user would not normally need to view them in the Salesforce user interface along with the record. Since this is a text field, if you were to include this field on a page layout, it would not render as an image – users would only see the text shown above when viewing the record detail in the Salesforce UI. Therefore, it would not be appropriate for end-users who upload their own images frequently (e.g. a scanned photograph of a damage claim) or wanted to view the actual image in Salesforce within the record detail page.
Option 3: Use a formula field to display an image
Building on option 2, you can leverage a Salesforce formula field to create the image path and also display the image within the Salesforce record detail. You would then drop the formula field into your S-Docs template with the Contains Rich Text option checked (as described in the previous option). The formula field would contain something similar to the following:
IMAGE("/CompanyIntranet/Products”+ myObject__c.ProductID__c + “.png")
This option requires some planning so that the image field name can be programmatically derived.
Option 4: Build an image URL within the S-Docs template
This is a combination of options 2 and 3, but would not require a formula field. You can use a record’s existing field value to help build the correct image path, but you create the full path value within the S-Docs template, not in the Salesforce field.
For example, to include a dynamic product image or agent's signature, you can use something similar to the following in your document template source:
lt#img src=quot#https://intranet/{{!Product2.ProductPath__c}}.png quot# /gt# lt#img src=quot#{{!Opportunity.Owner.SignatureURL__c}}quot# /gt#
The field value should be a URL that points to either an image in your Salesforce documents folder or an external image hosted on the public internet. The field should contain the entire path including the ‘http://’ prefix.
Note that Salesforce automatically generates relative URLs (e.g. src=“/servlets/…”), as opposed to full URLs (e.g. src=”https://na1.salesforce.com/servlets/...”). While S-Docs automatically adds in the correct base URL, images still may not appear for certain template formats (especially when you've migrated templates between orgs). We recommend building a full image URL in a custom field so that the base URL can be changed in one place if needed, as opposed to every template.
Discussion
Once you have inserted a marked-up field into your template, you will notice three sets of braces that surround your field, for example:
{{{!Product2.ProductImage__c}}}
The extra pair of curly braces instructs S-Docs to interpret this field rather than just displaying the stored value. Without this, S-Docs would not know whether a field containing the value “<img src=“//host/Product123Image.png” />” should be displayed as the text quoted or substituted with the actual image when rendered. Whenever you add a field using the template editor and click on the Contains Rich Text checkbox, S-Docs will evaluate the value regardless of the actual Salesforce field type (Rich Text or otherwise).
Dynamic Images with the DOC Template Format
For DOC templates, in order to ensure that your images are scaled correctly in the final generated document, it is important to check Embed Images in the Page Settings tab of the template editor.