# Merge Fields With Template Editor

## 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](/sdocs/template-architecture/inserting-merge-fields/additional-resources/escape-an-apostrophe-correctly-in-a-merge-field.md)
* [Mailing Address Fields](/sdocs/template-architecture/inserting-merge-fields/additional-resources/special-salesforce-mailing-address-fields.md)
* [CSS Styling with Merge Fields](/sdocs/template-architecture/template-authoring/css-styling-with-merge-fields.md)


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

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

The question should be specific, self-contained, and written in natural language.
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.
