S-Docs Render is a powerful feature that permits sections (or blocks) of text and data to display in your generated document only when a condition is met. This provides a mechanism to create a single template that can dynamically show and hide portions of the document based on conditional logic.
While you can also achieve simple dynamic rendering within your S-Docs templates by only using Salesforce formula fields (without the S-Docs Render feature), this approach has limitations and can be difficult to scale.
To address these limitations, S-Docs provides two levels of Rendering: Basic Render and Advanced Render.
The Basic Render feature can be used to show or hide a block of your S-Docs template based on a single condition. We suggest this approach first because it is simple and can meet most requirements.
For more complex requirements where advanced logic is needed, the S-Docs Advanced Render feature can be leveraged. The Advanced Render feature uses Salesforce APEX syntax to evaluate complex and compound logical statements.
LEVERAGING FORMULA FIELD
You can achieve simple rendering using only Salesforce formula fields. This technique works by using a formula field which returns either text or a blank value based on the conditional logic you set in the formula. That formula field is then simply merged into your S-Docs template just like any other merged field. While this is simple, you may reach the upper size limits of the formula field if you want to show large blocks of text.
For example, dynamically inserting "Terms and Conditions" in your document based on another field value should not be done with a formula field. Moreover, having text and logic split between your template and formula is not a good practice, as this becomes difficult to maintain.
Lastly, if you have many conditions in multiple S-Docs templates, this approach is not practical because it will require too many formula fields to be created. We therefore suggest this approach for only the simplest cases, or where the formula field already exists for other purposes. For example, if you already have a field called "Delivery Charge" and you want it to display "No Charge" for "Gold" tier customers, you may use a formula field like the one below:
BASIC S-DOCS RENDER USAGE
The S-Docs Render feature provides a mechanism to dynamically show or hide information without having to create additional templates for every use case. You add a render statement into your S-Docs template, and if it evaluates to TRUE, then the entire block (up to the closing ENDRENDER tag) is included; otherwise it is omitted. To use the S-Docs Render feature, you can edit the template source code, or click the Insert RENDER button. This document will focus on editing the source code yourself.
To begin, click the Source button in the template editor to toggle between the graphical view and the template source view. The source view can be edited by anyone with basic HTML knowledge. For example, you may want to display an additional paragraph in your document if the client lives in California. Here is a snippet that you would add to your S-Docs template source where you want the text to appear:
The basic S-Docs render feature is restricted to a single evaluation expression and it supports four basic comparators (==, !=, > and <).
If you require more complex conditional logic (e.g. compound conditions with AND, OR, CONTAINS, STARTSWITH etc) you can still achieve this with the Basic Render option, but you will need the help of a Salesforce formula field. The formula field can be used solely to perform your logical test – it does not need to appear in any page layouts visible to end users.
For example, if you wanted to show a paragraph in your template when BOTH the client's billing and shipping addresses are in California, you can do this with the Basic Render and a formula field. Again, the formula field performs the logical check and simply returns a single value that your S-Docs render statements then uses to control the rendering block. This technique provides a powerful and familiar way to handle conditional blocks without adding complexity or having to learn a specialized syntax.
Standard Salesforce Formula Field is used to define field named "SDOC_SHOW_PARAGRAPH__C":
Then leverage the formula field to control the render block within your S-Docs template source:
Render is also useful to determine if a value is empty or NULL. In the example below, we can create two render blocks. Since the value can only be null or NOT null, we are assured that only one of the render blocks below will be included in the final document output:
BASIC RENDER AND NESTING
S-Docs provides for 4 levels of nesting render statements. This allows you to place conditions within other conditions. Using nested render statements can also be leveraged to achieve compound logic as shown in the example below:
There is no limit on the number of render statements you place within other render statements, however you are limited to nesting them to a maximum of 4 levels deep. Note in the example above that you can have multiple "Render1" tags within the same parent "Render" tag. However, you must change the render tag name whenever you are nesting a render within another render statement. When doing this, you must change the name of the nested render tag to "RENDER1" "RENDER2" or "RENDER3" and this name must be different than any of its parent tags.
You must also be certain that all render statements are properly terminated (with an ENDRENDER tag) so that they do not intersect (overlap) with another render tag with the same name.
BASIC RENDER WITHOUT NESTING
S-Docs also uses AND (&&) and OR (||) in the RENDER statement, so you don't have to nest. A RENDER statement using AND (&&) can be leveraged to achieve logic as shown in the example below:
Similarly, OR (||) can be used as shown in the example below:
AND (&&) and OR (||) can be used concatenate multiple statements. For example:
A similar method using the Runtime Prompt can also show a prompt by letting the user choose to include or to not include the block of text.
'CONTAINS' AND 'NOT CONTAINS' STATEMENTS
In addition to checking for a string of quality with boolean functions, you can use 'CONTAINS' or 'NOT CONTAINS' to look for a specific string of quality. For example, a statement with 'CONTAINS' would look like:
And a statement with 'NOT CONTAINS' would look like: