> 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/how-to-format-text-dates-and-currency.md).

# How to Format Text, Dates, and Currency

Use this tutorial when you want one template to control how values render in the document body.

## What it looks like

After setup, one generated invoice gives the user all of this:

* A readable invoice date, such as `April 9, 2026`
* A formatted amount, such as `$4,222,300.80`
* Checkbox icons for payment options
* An uppercase billing block for customer details
* Reusable merge field patterns you can copy into other templates

This is the right end state for invoice, quote, and order templates that need clean output without changing the source data.

## When to use template attributes

Use template attributes when you need to change how a field renders inside the template body.

**Best for:**

* Formatting dates and numbers for business documents
* Showing checkbox or radio output from boolean fields
* Transforming text case without changing Salesforce data
* Reusing the same merge field pattern across similar fields

Use another feature when the problem is different:

* Use [Configure Document Generation Template Settings](/quick-start/template-building/customize-template-settings-document-generation.md) when you need file naming, save behavior, or page layout.
* Use [Getting Started with Conditional Logic](/quick-start/template-building/conditional-logic-tutorial.md) when content should appear only when conditions pass.
* Use [Get Started with Calculations](/quick-start/template-building/get-started-with-calculations.md) when you need derived values such as deposits, tax, or due dates.
* Use [Adding Tables (Like Products or Contacts) to Your Document](/quick-start/template-building/adding-tables-like-products-or-contacts-to-your-document.md) when you need child records or table output.

## Build an invoice template with template attributes

### What you'll configure

* Basic merge field structure
* `format-date` for invoice date
* `format-number` for currency values
* `checkbox` for payment options
* `ToUpperCase` for billing fields

**Estimated time:** 20 minutes

### Prerequisites

Before you start, make sure you have:

* Access to **S-Docs Templates**
* Permission to create or edit templates
* An S-Docs template related to `Opportunity`
* A test Opportunity with an Amount, Close Date, and Account
* Basic familiarity with merge fields such as `{{!Opportunity.Name}}`

If you are brand new to S-Docs syntax, start with a basic merge field tutorial first.

{% stepper %}
{% step %}

### Step 1: Open or create the template

Start with an Opportunity template that will generate an invoice.

1. Go to **S-Docs Templates** in Salesforce.
2. Open an existing template or click **New Template**.
3. Set **Related To Type** to `Opportunity`.
4. Set **Template Format** to `PDF`.
5. Open the template editor.

You now have a place to add template attributes in the document body.
{% endstep %}

{% step %}

### Step 2: Start with plain merge fields

Start with raw values first. This makes the attribute changes obvious.

Add this near the top of the template:

{% code title="invoice-baseline.html" %}

```html
<h1>Invoice</h1>
<p>Opportunity: {{!Opportunity.Name}}</p>
<p>Invoice Date: {{!Opportunity.CloseDate}}</p>
<p>Amount Due: {{!Opportunity.Amount}}</p>
```

{% endcode %}

What you just did:

* Added three plain merge fields with no attributes
* Confirmed the base object and field paths are correct
* Created a before state for the next formatting steps

How to read the syntax:

* `{{!` starts the merge field
* `Opportunity.CloseDate` points to one field on the base record
* Attributes come after the field path
* `}}` closes the merge field
  {% endstep %}

{% step %}

### Step 3: Add a formatted invoice date

A date attribute turns raw Salesforce date output into invoice-ready text.

Add this near the top of the template:

{% code title="invoice-header.html" %}

```html
<h1>Invoice</h1>
<p>Invoice Date: {{!Opportunity.CloseDate format-date="MMMM d, yyyy"}}</p>
```

{% endcode %}

What you just did:

* Applied `format-date` to `Opportunity.CloseDate`
* Used `MMMM d, yyyy` for month name, day, and four-digit year
* Created a readable invoice header without changing the source field

Why this pattern matters:

* The field path stays the same
* Only the attribute changes the output
* You can reuse this pattern on any date field
  {% endstep %}

{% step %}

### Step 4: Format the invoice amount

A number attribute lets you keep raw numeric data in Salesforce while showing clean currency in the document.

Add this below the date:

{% code title="invoice-total.html" %}

```html
<h2>Invoice Total</h2>
<p><strong>Amount Due: ${{!Opportunity.Amount format-number="#,###.##"}}</strong></p>
```

{% endcode %}

What you just did:

* Applied `format-number` to the amount field
* Added commas and two decimal places with `#,###.##`
* Kept the dollar sign outside the attribute for predictable output

Pattern to remember:

* Start with the raw field: `{{!Opportunity.Amount}}`
* Add one space
* Add the attribute: `format-number="#,###.##"`
* Keep visible text, such as `$`, outside the merge field
  {% endstep %}

{% step %}

### Step 5: Add payment method checkboxes

Use checkbox attributes when the source field is a true Salesforce checkbox field.

If these fields do not exist yet, create `Payment_by_Check__c` and `Payment_by_Credit_Card__c` on `Opportunity` before continuing.

Then add this block:

{% code title="payment-methods.html" %}

```html
<h3>Payment Methods</h3>
<p>
  {{!Opportunity.Payment_by_Check__c checkbox="true"}} Check<br>
  {{!Opportunity.Payment_by_Credit_Card__c checkbox="true"}} Credit Card
</p>
```

{% endcode %}

What you just did:

* Rendered boolean fields as checkbox icons instead of `true` or `false`
* Kept the labels readable for the final document
* Used a pattern you can swap to `checkbox="black"` or `checkbox="radio"` later

Merge field rule:

* Put the label outside the merge field
* Keep the `checkbox` attribute inside the same field
  {% endstep %}

{% step %}

### Step 6: Add an uppercase billing block

Text attributes are useful when the document needs a formal display style.

Add this below the invoice header or near the customer section:

{% code title="billing-block.html" %}

```html
<p>
  <strong>Bill To:</strong><br>
  {{!Opportunity.Account.Name ToUpperCase="true"}}<br>
  {{!Opportunity.Account.BillingStreet ToUpperCase="true"}}<br>
  {{!Opportunity.Account.BillingCity ToUpperCase="true"}},
  {{!Opportunity.Account.BillingState ToUpperCase="true"}}
  {{!Opportunity.Account.BillingPostalCode}}
</p>
```

{% endcode %}

What you just did:

* Converted account name and address lines to uppercase in the output only
* Left the postal code unchanged
* Applied the same attribute pattern across several related fields

Pattern to remember:

* Keep each field separate
* Repeat the same attribute on each line you want transformed
* Leave fields unchanged when you want their original display
  {% endstep %}

{% step %}

### Step 7: Test a few merge field variations

Once the base version works, swap one pattern at a time.

Try one of these date alternatives:

{% code title="date-variations.html" %}

```html
{{!Opportunity.CloseDate format-date="MM/dd/yyyy"}}
{{!Opportunity.CloseDate format-date="dd.MM.yyyy"}}
{{!Opportunity.CloseDate format-date="EEEE, MMMM d, yyyy"}}
```

{% endcode %}

Try one of these number alternatives:

{% code title="number-variations.html" %}

```html
${{!Opportunity.Amount format-number="#,###"}}
€{{!Opportunity.Amount format-number="#.###,##"}}
£{{!Opportunity.Amount format-number="#,###.00"}}
```

{% endcode %}

What you just did:

* Reused the same merge field with different attributes
* Changed output without changing the Salesforce data
* Built patterns you can copy into quote or order templates
  {% endstep %}

{% step %}

### Step 8: Save and test the template

Generate the invoice from a real Opportunity before adding variations.

1. Click **Save** in the template editor.
2. Open a test Opportunity with the fields you used.
3. Generate the template.
4. Verify the output.

Check these results:

* The invoice date uses a readable format
* The amount shows commas and decimals
* The payment fields render as checkboxes
* The billing block appears in uppercase
* The raw merge fields no longer appear in their default Salesforce format
  {% endstep %}
  {% endstepper %}

## Guardrails and limits

### Merge field syntax rules

* **Always** start with `{{!` and end with `}}`.
* **Always** keep attributes inside the same merge field.
* **Always** leave a space between the field name and the first attribute.
* **Always** keep markup outside the merge field.
* If markup breaks the merge field, S-Docs prints the syntax as literal text.

### Date and number formatting rules

* **Use** lowercase `yyyy` for the year in `format-date` patterns.
* **Type** currency symbols outside `format-number`.
* If the pattern is wrong, values can render in an unexpected format or stay unformatted.

### Checkbox and output limits

* **Use** `checkbox` only with boolean fields.
* **Expect** checkbox rendering to work best in PDF templates.
* If you apply `checkbox` to the wrong field type, the document can show raw values instead of icons.

### Testing rules

* **Generate** one test document after each major syntax change.
* **Use** a record with real values and known checkbox states.
* If you skip testing, syntax problems usually surface only in final output.


---

# 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/how-to-format-text-dates-and-currency.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.
