> For the complete documentation index, see [llms.txt](https://help.sdocs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.sdocs.com/sdocs/template-architecture/inserting-merge-fields/merge-fields-with-template-editor.md).

# Merge Fields With Template Editor

Learn what merge fields are, how to add them to a template, and which attributes are most useful day to day.

## Inserting Merge Fields

Merge fields pull live Salesforce data into an S-Docs template.

They act as placeholders. At generation time, S-Docs replaces them with record values.

### What a merge field looks like

Use this pattern:

```
{{!Object.Field}}
```

Examples:

```
{{!Opportunity.Name}}
{{!Opportunity.Account.Name}}
{{!Contact.Email}}
```

You can also apply formatting attributes.

Example:

```
{{!Opportunity.CloseDate format-date="yyyy-MM-dd"}}
```

### How to add a merge field

{% stepper %}
{% step %}

### Choose the record value

Identify the object and field you want to merge.

Example: `Opportunity.Name`
{% endstep %}

{% step %}

### Insert the merge field into the template

Place your cursor where the value should appear.

Then insert or type the merge field syntax:

```
{{!Opportunity.Name}}
```

{% endstep %}

{% step %}

### Add an attribute if needed

Attributes change how the value renders.

Example:

```
{{!Opportunity.Amount format-number="#,###.##"}}
```

{% endstep %}

{% step %}

### Save and test

Generate a document from a real record.

Confirm the value and formatting are correct.
{% endstep %}
{% endstepper %}

### Quick examples

#### Plain text field

```
{{!Account.Name}}
```

#### Parent relationship field

```
{{!Opportunity.Account.Name}}
```

#### Number formatting

```
{{!Opportunity.Amount format-number="#,###.##"}}
```

#### Render rich text content

```
{{{!Object.Rich_Text_Field__c}}}
```

#### Replace characters or values

```
{{!Contact.LastName replaceAll="',\\'"}}
```

### Quick reference: common merge field attributes

This is a practical reference. It covers the most commonly documented attributes.

#### `replaceAll`

Replaces matching text inside the merged value.

Use it for cleanup, escaping, or value swaps.

```
{{!Object.Field replaceAll="old,new"}}
{{!Contact.LastName replaceAll="',\\'"}}
```

Use multiple pairs when needed.

{% hint style="info" %}
Use `#comma#` if a replacement value must contain a comma.
{% endhint %}

#### `format-number`

Formats numeric output.

```
{{!Opportunity.Amount format-number="#,###.##"}}
{{!test.unitprice format-number="-#.###,##"}}
```

Useful for currency, decimals, phone-like masks, and localized separators.

#### Rich text output and triple braces

Use triple braces when you want to preserve formatting from a rich text field.

```
{{{!Object.Rich_Text_Field__c}}}
```

Use this when you want line breaks or markup to remain in the output.

#### `format-date`

Formats date and datetime values.

Example:

```
{{!Opportunity.CloseDate format-date="yyyy-MM-dd"}}
```

Use this when you need a predictable date format.

### Common issues

* Wrong object or field API name
* Missing relationship path
* Special characters not escaped
* Rich text output not formatted as expected

### Related articles

* [Escape an Apostrophe Correctly in a Merge Field](broken://spaces/WKNnJmhJBQwhdk5WBFsi/pages/6bf519bef231ce5d7d8edc8cd875b27750faa0d7)
* [Mailing Address Fields](https://help.sdocs.com/sdocs/template-architecture/inserting-merge-fields/additional-resources/special-salesforce-mailing-address-fields.md)
* [CSS Styling with Merge Fields](https://help.sdocs.com/sdocs/template-architecture/template-authoring/css-styling-with-merge-fields.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://help.sdocs.com/sdocs/template-architecture/inserting-merge-fields/merge-fields-with-template-editor.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
