Expressions
Merge Fields
Built-in Functions
REST API Endpoints
REST API Objects

# Expressions

DocumentEngine expressions are the basic unit of a DocumentEngine template. You can use them alone in a {{mustache}}, pass them to a DocumentEngine helper, or use them as values in hash arguments.

# Basic Usage

DocumentEngine expressions are some contents enclosed by double curly braces {{}}. In the below template, firstname is a variable that is enclosed by double curly braces, which is said to be an expression.

template

If the below input object is applied to the template

input

Expressions are compiled to produce the output as follows:

output

# Path expressions

DocumentEngine expressions can also be dot-separated paths.

template

This expression looks up the person property in the input object and in turn looks up the firstname and lastname property within the person object.

Pass the below input object to the template

input

Output will be generated as below

output

DocumentEngine also supports a deprecated / syntax, so you could write the above template as:

template

# Changing the context

Some helpers like #with and #each allow you to dive into nested objects. When you include ../ segments in your path, DocumentEngine will change back into the parent context.

template

Even though the name is printed while in the context of a comment, it can still go back to the main context (the root-object) to retrieve the prefix.

WARNING

The exact value that ../ will resolve to varies based on the helper that is calling the block. Using ../ is only necessary when context changes. Children of helpers such as {{#each}} would require the use of ../ while children of helpers such as {{#if}} do not.

In this example all of the above reference the same prefix value even though they are located within different blocks. This behavior is new as of DocumentEngine 4; the release notes discuss the prior behavior as well as the migration plan. DocumentEngine also allows for name conflict resolution between helpers and data fields via a this reference:

# Literal segments

Identifiers may be any unicode character except for the following:

Whitespace ! " # % & ' ( ) * + , . / ; < = > @ [ \ ] ^ ` { | } ~

In addition, the words true, false, null and undefined are only allowed in the first part of a path expression.

To reference a property that is not a valid identifier, you can use segment-literal notation, [. You may not include a closing ] in a path-literal, but all other characters are allowed.

JavaScript-style strings, " and ', may also be used instead of [ pairs.

template

# HTML-escaping

In DocumentEngine, the values returned by the {{expression}} are HTML-escaped. Say, if the expression contains &, then the returned HTML-escaped output is generated as &amp;. If you don't want DocumentEngine to escape a value, use the "triple-stash", {{{:

In the below template, you can learn how to produce the HTML escaped and raw output.

template

Pass the special characters to the template

input

Expressions enclosed by "triple-stash" ({{{) produce the raw output. Otherwise, HTML-escaped output is generated as below.

output

# Whitespace Control

Template whitespace may be omitted from either side of any mustache statement by adding a ~ character by the braces. When applied all whitespace on that side will be removed up to the first DocumentEngine expression or non-whitespace character on that side.

with this context:

results in output sans newlines and formatting whitespace:

This expands the default behavior of stripping lines that are "standalone" helpers (only a block helper, comment, or partial and whitespace).

will render

# Escaping DocumentEngine expressions

DocumentEngine content may be escaped in one of two ways, inline escapes or raw block helpers. Inline escapes created by prefixing a mustache block with \. Raw blocks are created using {{{{ mustache braces.

Raw blocks operate in the same manner as other block helpers with the distinction of the child content is treated as a literal string.

# Merge Fields (Salesforce Data Binding)

Merge fields let you pull Salesforce data directly into your templates. They support:

  • Any field on the base record
  • Traversal up or down the object hierarchy (e.g., {{:Opportunity.:Owner.:Name}})
  • Related lists without extra calls (e.g., Quote Line Items, child records)
  • Internationalized labels via {{::labels.*}}
  • Formatting with built-in helpers like date, currency, formatNumber

# Basic Syntax

Use the colon-prefixed path to bind Salesforce fields. Labels are available via ::labels for i18n.

Traverse parent/child relationships by chaining segments. Use .: to step through related objects.

TIP

You can combine relationship paths with helpers. For example, format dates from the base record or a related record using date.

Iterate related lists (e.g., {{#each :QuoteLineItems}}) using {{#each}}. Inside the loop, fields resolve in the row context.

WARNING

When you are inside an {{#each}} block, use ../ to access parent context values (such as totals or flags on the parent record).

# Conditional Output

Use {{#if}} and logic helpers to render only when values exist.

# Formatting

Merge fields work with built-in helpers for dates, currency, and numbers.

# Advanced Selection Examples

Filter and count items in related lists with selectors and conditions.

# Full Example

A compact quote header demonstrating labels, fields, relationships, conditionals, and formatting: