# Word Doc Autofill

If you use a Word doc template, you can include variables in your document via double-curly brace syntax (`{{Field1}}`). Feathery will automatically replace variables with the corresponding field value when you fill them out.

{% hint style="warning" %}
Fields can only contain **letters, numbers, and underscores** when being used in Word Doc Autofill. Other characters may cause the generation to fail by reading the field name as a formula instead.
{% endhint %}

## Creating the Word Doc Template

Feathery supports [Jinja templating logic](https://documentation.bloomreach.com/engagement/docs/jinja-syntax) for advanced use cases such as conditionally showing/hiding sections, generating sections in a loop, formulas, and more.

### Conditional Logic

You can support conditionally showing or hiding any content / pages using the `{%p` syntax show below:

```
{%p if display_paragraph %}
One or many paragraphs
{%p endif %}
```

In this example, we have a checkbox field called `display_paragraph` in our form that is either true or false.

The first and last paragraphs (those containing `{%p ... %}` tags) will never appear in generated Word doc, regardless of the `display_paragraph` value.

Here only:

```
One or many paragraphs
```

will appear in the generated docx if `display_paragraph` is True, otherwise, no paragraph at all are displayed.

You can insert anything within the tag, such as paragraphs, whole pages, etc.

### Embed Images

To embed an image into the document that was pulled from a form submission, use the following Jinja syntax:

```
{{ <FileUploadFieldId>__Image_<width>_<height> }}
```

`FileUploadFieldId` is the ID of the file upload field that the image to embed was uploaded to. `Width` is the width of the embedded image, in millimeters. `Height` is the height of the embedded image, in millimeters.

## Set Template Field Values

After your Word template has been uploaded, you can use [logic rules](https://docs.feathery.io/platform/build-forms/advanced-logic/visual-rule-builder/set-field-value-action) and hidden fields to set the template fields to custom values. This allows you to achieve complex logic that was set up during the templating step.

<figure><img src="https://640450274-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHAVngDAEk3s8Bw7P6Ntz%2Fuploads%2FuTrzqxsUrMPqTc13ud2m%2Fword_logic.png?alt=media&#x26;token=677b0aa1-f0e1-4e2d-ba18-3e8cb46882db" alt="" width="375"><figcaption><p>Custom rules and hidden fields can be combined to create complex logic.</p></figcaption></figure>

## Document Workflow

Once you've mapped your document, you can integrate it into your existing workflow for filling and routing to the desired location. For example, you can include your document as an attachment in a custom [email integration](https://feathery.io/integrations/email) to be sent to recipients.
