> 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/quick-start/template-building/create-your-first-word-template.md).

# Create Your First Word Template

## What You'll Learn

* Create a DOCX template record for S-Docs
* Generate Microsoft template syntax from the template editor
* Place bracketed merge fields into a Word document
* Add conditional logic and related list syntax to a DOCX file
* Upload the finished DOCX file and test generation

## What You'll Build

In this tutorial, you will build a simple Word-based quote template for `Opportunity`.

By the end, you will have:

* A DOCX template record tied to `Opportunity`
* A Word document with bracketed S-Docs merge fields
* A conditional note that appears only for one stage
* A related list pattern you can paste into a Word table
* A finished DOCX file uploaded back to S-Docs

**Estimated time:** 20 minutes

## Prerequisites

Before you start, make sure you have:

* Access to **S-Docs Templates** in Salesforce
* Permission to create or edit templates
* Microsoft Word or another editor that saves valid `.docx` files
* One test `Opportunity` with an Account, Stage, and Amount
* Basic familiarity with merge fields such as `{{!Opportunity.Name}}`

{% hint style="info" %}
DOCX syntax follows the same Microsoft template pattern used by PPTX and XLSX templates.
{% endhint %}

{% stepper %}
{% step %}

### Step 1: Create the DOCX template record

Start by creating the Salesforce template record before you build the Word file.

1. Open the App Launcher.
2. Search for `S-Docs`.
3. Open **S-Docs Templates**.
4. Click **New**.
5. Set **Related To Type** to `Opportunity`.
6. Set **Template Format** to `DOCX`.
7. Enable **Enable New Microsoft Template Upload**.
8. Click **Save**.

This record gives you a place to configure settings and generate the syntax you will paste into Word.
{% endstep %}

{% step %}

### Step 2: Open the template editor and generate syntax

The template editor is your syntax builder for Microsoft templates.

1. Open the new template record.
2. Click **Template Editor**.
3. Use **Insert Field** to choose the fields you want in the document.
4. Copy each generated value from the output box.

For DOCX templates, merge fields, related lists, and conditional blocks must be enclosed in square brackets.

If you need literal bracket characters in the document, use `BRACKETOPEN` and `BRACKETCLOSE`.
{% endstep %}

{% step %}

### Step 3: Build the document body in Microsoft Word

Now create the visible document in Word.

Start with a simple quote header and summary.

Paste this pattern into your DOCX file:

{% code title="quote-summary.docx.txt" %}

```plaintext
Quote for [{{!Opportunity.Account.Name}}]

Opportunity: [{{!Opportunity.Name}}]
Stage: [{{!Opportunity.StageName}}]
Close Date: [{{!Opportunity.CloseDate}}]
Amount: [{{!Opportunity.Amount}}]
```

{% endcode %}

What you just did:

* Added basic merge fields for the base record
* Used the bracketed Microsoft template syntax
* Created a working first version before adding logic
  {% endstep %}

{% step %}

### Step 4: Add one conditional block

Use conditional logic when part of the document should appear only for some records.

Add this block below the summary:

{% code title="conditional-note.docx.txt" %}

```plaintext
[<!--RENDER={{!Opportunity.StageName}}=="Proposal/Price Quote"-->]
This quote is in active review.
[<!--ENDRENDER-->]
```

{% endcode %}

What you just did:

* Added a stage-based rule to the DOCX file
* Kept the full conditional block inside bracketed Microsoft syntax
* Created one safe pattern you can reuse with other fields later
  {% endstep %}

{% step %}

### Step 5: Save the DOCX file

Save the file locally before you upload it.

Use a clear file name such as `opportunity-quote-template.docx`.

After saving, reopen the file once to confirm the content and formatting still look correct.
{% endstep %}

{% step %}

### Step 6: Upload the DOCX file to the template

Upload the finished Word file back to the S-Docs template record.

If you are using S-Docs Summer 2025 (`v10.0`) or later:

1. Return to the template record.
2. Click **Upload Files**.
3. Select the `.docx` file.

If you are using an earlier version, upload the file from the template editor.

Once the upload completes, the template is ready for generation.

{% hint style="warning" %}
Microsoft templates with **Enable New Microsoft Template Upload** checked are generated through S-Docs LWCs or the SDK.
{% endhint %}
{% endstep %}

{% step %}

### Step 7: Generate a test document

Test the template with a real `Opportunity` record.

1. Open a test opportunity.
2. Generate the DOCX template.
3. Download or preview the generated file.
4. Verify the output.

Check these results:

* The account and opportunity names resolve correctly
* The stage and amount display real record values
* The conditional note appears only when the stage is `Proposal/Price Quote`
* No raw S-Docs syntax appears in the document
  {% endstep %}
  {% endstepper %}

## Common DOCX syntax patterns

Use the patterns below when you expand the template.

### Merge field syntax

DOCX templates require brackets around merge fields.

Use **Insert Field** in the template editor to generate the syntax.

Then:

1. Select the field.
2. Apply any formatting.
3. Copy the generated syntax.
4. Paste it into Microsoft Word.

### Related list syntax

To insert a related list into a DOCX template, generate the related list syntax and paste it into a prebuilt Word table.

Use **Insert Related List** at the top of the template editor to build the related list.

When the related list is ready:

1. Open the **Get Related List** tab in the related list menu.
2. Copy the generated source.
3. In Word, create a styling table with:
   * a header row with your intended header text
   * an odd row
   * an even row
4. Paste the related list code into the cell in the first column under the header.

{% hint style="info" %}
The same related list placement pattern used in Microsoft PowerPoint templates also applies to DOCX.
{% endhint %}

### Conditional logic syntax

Use **Insert Conditional Logic** at the top of the template editor to open the logic builder.

Build the condition, then copy the generated output into Word.

If the rendered content contains merge fields, those merge fields must also be enclosed in brackets.

{% code title="docx-conditional-logic.txt" %}

```plaintext
[<!--RENDER={{!Opportunity.Amount}} > 10000-->]
High-value quote
[<!--ENDRENDER-->]
```

{% endcode %}

{% hint style="warning" %}
Do not place `RENDER` tags on the same line as the `LINEITEMS` block.
{% endhint %}

### Additional syntax

#### Rich text images

To display images stored in rich text fields, use three curly braces instead of two.

{% code title="docx-rich-text-image.txt" %}

```plaintext
[{{{!Object.FieldName}}}]
```

{% endcode %}

To adjust image dimensions:

1. Open the **Document Options** tab in the template editor.
2. Scroll to **Other Options**.
3. Enter the size in **Rich Text Image Dimensions**.

#### Named queries

If you use named queries in a DOCX template, convert them to the bracketed Microsoft template syntax.

If the named query looks like this:

{% code title="named-query-standard.txt" %}

```plaintext
<!--{{!<LineItemsSOQL>
...
</LineItemsSOQL>}}-->
{{!myQuery1.fieldname}}
```

{% endcode %}

Update it to this:

{% code title="named-query-docx.txt" %}

```plaintext
[{{!<LineItemsSOQL>
...
</LineItemsSOQL>}}]
[{{!myQuery1.fieldname}}]
```

{% endcode %}

DOCX templates support named query `filter` and `offset`.

## Common Issues and Solutions

<details>

<summary>"The document shows raw merge field syntax"</summary>

Check these items:

* Confirm each merge field is wrapped in square brackets
* Confirm the merge field itself still uses `{{! ... }}`
* Reupload the DOCX file after fixing the syntax

</details>

<details>

<summary>"The document generates, but values are blank"</summary>

Check these items:

* Confirm the template uses **Related To Type** `Opportunity`
* Confirm the test record has values in the fields you used
* Recopy the field syntax from **Insert Field** if needed

</details>

<details>

<summary>"The conditional note never appears"</summary>

Check these items:

* Confirm both `RENDER` tags are wrapped in square brackets
* Confirm the compared value matches the record value exactly
* Test the same record value directly in the document first

</details>

<details>

<summary>"My related list formatting looks wrong"</summary>

Check these items:

* Confirm the related list code was pasted into the first cell under the header
* Confirm the Word table includes header, odd, and even rows
* Regenerate the related list syntax after query changes

</details>

<details>

<summary>"My latest DOCX changes do not show up"</summary>

Check these items:

* Save the Word file before uploading it
* Upload the newest version of the `.docx` file
* Generate a new document after each upload

</details>

<details>

<summary>"DOCX generation is not available"</summary>

Check these items:

* Enable **Enable New Microsoft Template Upload** on the template
* Confirm the template was uploaded as a `.docx` file
* Generate through an S-Docs LWC or the SDK when the new Microsoft upload flow is enabled

</details>

## What You've Learned

✅ Created a DOCX template record for `Opportunity`\
✅ Used the template editor to generate Microsoft template syntax\
✅ Added bracketed merge fields to a Word document\
✅ Added conditional logic and related list patterns\
✅ Uploaded and tested a DOCX template in S-Docs

## Next Steps

* Use [Template Attributes Tutorial](/quick-start/template-building/how-to-format-text-dates-and-currency.md) to format values inside the document.
* Use [Getting Started with Conditional Logic](/quick-start/template-building/conditional-logic-tutorial.md) to add more conditions.
* Use [Creating Your First Named Query](/quick-start/template-building/creating-your-first-named-query-tutorial.md) to reuse query results in Microsoft templates.
* Use [Build and Upload a PPTX Template](/quick-start/template-building/build-and-upload-a-pptx-template.md) if you also build PowerPoint templates.
* Use [Add S-Docs Lightning Components to a Record Page](/quick-start/document-generation/add-s-docs-lightning-components-to-a-record-page.md) to expose the template for record-page generation.

## Practice Exercise

Build a second DOCX template for `Opportunity` that includes:

1. A title with `Opportunity.Name`
2. A customer line with `Opportunity.Account.Name`
3. A stage-based conditional note
4. A related list placeholder in a Word table
5. One test generation from a real record

Bonus challenges:

* Add one more merge field from a related record
* Add a named query to the DOCX file
* Rebuild the same pattern for `Account`


---

# 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 dynamically by asking a question.

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

```
GET https://help.sdocs.com/quick-start/template-building/create-your-first-word-template.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
