> 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/advanced-template-logic.md).

# Advanced Template Logic

- [Insert Data Tables](https://help.sdocs.com/sdocs/advanced-template-logic/related-lists.md): Build dynamic S-Docs data tables with related lists and direct SOQL. Start here for task guides, Microsoft template patterns, and troubleshooting.
- [How to: Filter and Sort a Related List](https://help.sdocs.com/sdocs/advanced-template-logic/related-lists/how-to-filter-and-sort-a-related-list.md): Use WHERE, ORDER BY, LIMIT, and relationship fields to return only the rows you need.
- [How to: Format and Summarize a Related List](https://help.sdocs.com/sdocs/advanced-template-logic/related-lists/how-to-format-and-summarize-a-related-list.md): Apply column attributes, conditional output, and aggregate SOQL to make related lists easier to read.
- [How to: Create a Table In Microsoft Templates (DOCX, PPTX)](https://help.sdocs.com/sdocs/advanced-template-logic/related-lists/how-to-create-a-table-in-microsoft-templates-docx-pptx.md): Build a DOCX related list table by placing a Word table between tableformat tags and mapping each column to a SOQL field.
- [Additional Troubleshooting](https://help.sdocs.com/sdocs/advanced-template-logic/related-lists/additional-troubleshooting.md)
- [Intentional Text Overflow on Related List](https://help.sdocs.com/sdocs/advanced-template-logic/related-lists/additional-troubleshooting/intentional-text-overflow-on-related-list.md)
- [Conditional Formatting for Color of Cells in a Related List](https://help.sdocs.com/sdocs/advanced-template-logic/related-lists/additional-troubleshooting/conditional-formatting-for-color-of-cells-in-a-related-list.md)
- [Formatting with GroupbySum](https://help.sdocs.com/sdocs/advanced-template-logic/related-lists/additional-troubleshooting/formatting-with-groupbysum.md)
- [Single Query/Multi-Column List Output](https://help.sdocs.com/sdocs/advanced-template-logic/related-lists/additional-troubleshooting/single-query-multi-column-list-output.md)
- [Use lineitemsSOQL for multiple filtered related lists](https://help.sdocs.com/sdocs/advanced-template-logic/related-lists/additional-troubleshooting/related-lists-display-same-values-converting-lineitems-to-lineitemssoql.md): Avoid shared filter behavior when one template contains more than one filtered related list.
- [Use Conditional Logic](https://help.sdocs.com/sdocs/advanced-template-logic/conditional-logic.md): Learn how to control template output with RENDER statements. Start with the tutorial, move to task-based guidance, then use the reference pages for syntax and examples.
- [Quick Setup: Conditional Logic](https://help.sdocs.com/sdocs/advanced-template-logic/conditional-logic/conditional-logic-how-to.md)
- [Quick Setup: Conditional Logic With Microsoft Templates (DOCX, PPTX, XLSX)](https://help.sdocs.com/sdocs/advanced-template-logic/conditional-logic/quick-setup-conditional-logic-with-microsoft-templates-docx-pptx-xlsx.md): Learn how to use RENDER statements in DOCX templates with bracketed Microsoft template syntax.
- [Handle Escaped Characters in RENDER Statements](https://help.sdocs.com/sdocs/advanced-template-logic/conditional-logic/handle-escaped-characters-in-render-statements.md)
- [Retrieve and Reuse Data](https://help.sdocs.com/sdocs/advanced-template-logic/named-query.md): Use SOQL once, then reuse returned values anywhere in your S-Docs template for calculations, headers, and dynamic content.
- [How To: Advanced Data Retrieval with Named Queries](https://help.sdocs.com/sdocs/advanced-template-logic/named-query/how-to-advanced-data-retrieval-with-named-queries.md): Use aggregates, filters, offsets, and grouped results to return exactly the values you need from a named query.
- [How To: Chain Named Queries with queryname2](https://help.sdocs.com/sdocs/advanced-template-logic/named-query/guide-for-using-queryname2.md): Use queryname2 when a second named query depends on a value returned by a first named query.
- [Format Data with Template Attributes](https://help.sdocs.com/sdocs/advanced-template-logic/template-attributes.md): Learn how template attributes format values, related lists, and document layout in S-Docs. Start with the tutorial, jump to task guides, or use the reference for exact syntax.
- [Template Attributes (How-to Guides)](https://help.sdocs.com/sdocs/advanced-template-logic/template-attributes/template-attributes-how-to-guides.md): Task-based guides for common template attribute formatting and layout needs.
- [How To: Format Currency Values](https://help.sdocs.com/sdocs/advanced-template-logic/template-attributes/template-attributes-how-to-guides/how-to-format-currency-values.md): Learn how to format currency amounts with symbols, separators, decimals, and related list columns.
- [How To: Display Dates in Different Formats](https://help.sdocs.com/sdocs/advanced-template-logic/template-attributes/template-attributes-how-to-guides/how-to-display-dates-in-different-formats.md): Format Salesforce dates into readable US, long, European, or custom date patterns.
- [How To: Format Date and Time Together](https://help.sdocs.com/sdocs/advanced-template-logic/template-attributes/template-attributes-how-to-guides/how-to-format-date-and-time-together.md): Show date and time together, including 12-hour, 24-hour, and timezone-aware output.
- [How To: Show Checkboxes on Forms](https://help.sdocs.com/sdocs/advanced-template-logic/template-attributes/template-attributes-how-to-guides/how-to-show-checkboxes-on-forms.md): Display boolean fields as checkbox or radio images in PDF templates.
- [How To: Convert Text to Uppercase or Lowercase](https://help.sdocs.com/sdocs/advanced-template-logic/template-attributes/template-attributes-how-to-guides/how-to-convert-text-to-uppercase-or-lowercase.md): Force text into uppercase or lowercase for addresses, emails, and document styling.
- [How To: Create Multilingual Documents](https://help.sdocs.com/sdocs/advanced-template-logic/template-attributes/template-attributes-how-to-guides/how-to-create-multilingual-documents.md): Output translated values with Translation Workbench, substitute, or toLabel().
- [How To: Replace Values with Different Text](https://help.sdocs.com/sdocs/advanced-template-logic/template-attributes/template-attributes-how-to-guides/how-to-replace-values-with-different-text.md): Swap raw values for user-friendly labels with substitute and replaceAll.
- [Picklist Values: Replace Semicolon with Comma](https://help.sdocs.com/sdocs/advanced-template-logic/template-attributes/template-attributes-how-to-guides/how-to-replace-values-with-different-text/picklist-values-replace-semi-colon-with-comma.md): Replace semicolon-delimited field output with commas in merge fields and related list columns.
- [How To: Conditionally Show/Hide Table Columns](https://help.sdocs.com/sdocs/advanced-template-logic/template-attributes/template-attributes-how-to-guides/how-to-conditionally-show-hide-table-columns.md): Show or hide related list columns based on record conditions.
- [How To: Display Different Values Based on Conditions](https://help.sdocs.com/sdocs/advanced-template-logic/template-attributes/template-attributes-how-to-guides/how-to-display-different-values-based-on-conditions.md): Render different cell values based on row-level conditions in lineitemsSOQL.
- [How To: Format Line Items Without Tables](https://help.sdocs.com/sdocs/advanced-template-logic/template-attributes/template-attributes-how-to-guides/how-to-format-line-items-without-tables.md): Output related list data as text, not tables, using prefixes and postfixes.
- [How To: Create Custom Table Layouts](https://help.sdocs.com/sdocs/advanced-template-logic/template-attributes/template-attributes-how-to-guides/how-to-create-custom-table-layouts.md): Build custom table structures with merged cells, colspan, and row control.
- [How To: Add Custom Headers and Footers to Tables](https://help.sdocs.com/sdocs/advanced-template-logic/template-attributes/template-attributes-how-to-guides/how-to-add-custom-headers-and-footers-to-tables.md): Add custom headers, section breaks, and summary rows to related list tables.
- [How To: Handle Null or Empty Values](https://help.sdocs.com/sdocs/advanced-template-logic/template-attributes/template-attributes-how-to-guides/how-to-handle-null-or-empty-values.md): Show fallback text when fields are null or empty.
- [How To: Display Salesforce Encrypted Fields](https://help.sdocs.com/sdocs/advanced-template-logic/template-attributes/template-attributes-how-to-guides/how-to-display-salesforce-encrypted-fields.md): Show encrypted Salesforce field values in S-Docs and avoid common query sorting errors.
- [How To: Generate Checks and Banking Documents](https://help.sdocs.com/sdocs/advanced-template-logic/template-attributes/template-attributes-how-to-guides/how-to-generate-checks-and-banking-documents.md): Use MICR and OCR formatting for checks and banking documents.
- [How To: Work with Right-to-Left Languages](https://help.sdocs.com/sdocs/advanced-template-logic/template-attributes/template-attributes-how-to-guides/how-to-work-with-right-to-left-languages.md): Format templates for right-to-left languages like Hebrew and Arabic.
- [How To: Number Table Rows](https://help.sdocs.com/sdocs/advanced-template-logic/template-attributes/template-attributes-how-to-guides/how-to-number-table-rows.md): Add row numbers to related list tables and control the starting index.
- [How To: Create Multi-Page Documents with Page Breaks](https://help.sdocs.com/sdocs/advanced-template-logic/template-attributes/template-attributes-how-to-guides/how-to-create-multi-page-documents-with-page-breaks.md): Control page breaks and keep content together in multi-page documents.
- [How To: Add Email Recipients from Related Lists](https://help.sdocs.com/sdocs/advanced-template-logic/template-attributes/template-attributes-how-to-guides/how-to-add-email-recipients-from-related-lists.md): Pull related list email addresses into To, CC, or BCC recipients.
- [How To: Split Field Values into Individual Cells](https://help.sdocs.com/sdocs/advanced-template-logic/template-attributes/template-attributes-how-to-guides/how-to-split-field-values-into-individual-cells.md): Split field text into fixed-width cells for forms and character boxes.
- [How To: Display Long URLs or Text Without Breaking Layout](https://help.sdocs.com/sdocs/advanced-template-logic/template-attributes/template-attributes-how-to-guides/how-to-display-long-urls-or-text-without-breaking-layout.md): Wrap long URLs or serial numbers without breaking the layout.
- [How To: Work with Rich Text Fields](https://help.sdocs.com/sdocs/advanced-template-logic/template-attributes/template-attributes-how-to-guides/how-to-work-with-rich-text-fields.md): Preserve or strip formatting when working with rich text fields.
- [Perform Calculations](https://help.sdocs.com/sdocs/advanced-template-logic/perform-calculations.md)
- [Error: Incorrect Format. First Argument in Date Arithmetic Should Be a Date](https://help.sdocs.com/sdocs/advanced-template-logic/perform-calculations/error-incorrect-format.-first-argument-in-date-arithmetic-should-be-a-date.md)
- [Math Tags Null Value Error: Ending Position Out of Bounds (22) Stack Invalid Double](https://help.sdocs.com/sdocs/advanced-template-logic/perform-calculations/math-tags-null-value-error-ending-position-out-of-bounds-22-stack-invalid-double.md)
- [Build Reusable Templates](https://help.sdocs.com/sdocs/advanced-template-logic/build-reusable-templates.md)
- [Component Template How-to Article](https://help.sdocs.com/sdocs/advanced-template-logic/build-reusable-templates/component-template-how-to-article.md)
- [Component (DOCX)](https://help.sdocs.com/sdocs/advanced-template-logic/build-reusable-templates/component-template-how-to-article/component-docx.md): Use DOCX component templates in DOCX parent templates.
- [PDF-Upload as a Component](https://help.sdocs.com/sdocs/advanced-template-logic/build-reusable-templates/component-template-how-to-article/pdf-upload-as-a-component.md): Merge PDF-Upload templates into supported parent templates.
- [Using Component Queries](https://help.sdocs.com/sdocs/advanced-template-logic/build-reusable-templates/component-template-how-to-article/using-component-queries.md): Repeat a component once per record returned by a SOQL query.
- [Convert a Component Query to the Optimized Query Model](https://help.sdocs.com/sdocs/advanced-template-logic/build-reusable-templates/component-template-how-to-article/using-component-queries/convert-a-component-query-from-method-1-to-method-2.md)
- [Combining Components with Render Logic](https://help.sdocs.com/sdocs/advanced-template-logic/build-reusable-templates/component-template-how-to-article/combining-components-with-render-logic.md): Use conditional logic inside component templates.
- [Dynamic Components](https://help.sdocs.com/sdocs/advanced-template-logic/build-reusable-templates/component-template-how-to-article/dynamic-components.md): Choose which component to render at runtime based on Salesforce data.
- [Adding Headers & Footers from Components in PDF Templates](https://help.sdocs.com/sdocs/advanced-template-logic/build-reusable-templates/component-template-how-to-article/adding-headers-footers-from-components-in-pdf-templates.md)
- [Setup Translations](https://help.sdocs.com/sdocs/advanced-template-logic/translations.md): Choose the right translation method for the UI, picklist values, field labels, and document content.
- [Translating Document Content](https://help.sdocs.com/sdocs/advanced-template-logic/translations/translating-document-content-in-s-docs.md): Translate picklist values, field labels, and related list picklist output with Salesforce Translation Workbench.
- [How to: Translate Merge Fields and Field Labels](https://help.sdocs.com/sdocs/advanced-template-logic/translations/translating-document-content-in-s-docs/how-to-translate-merge-fields-and-field-labels.md): Use Translation Workbench to translate picklist merge field output, field labels, and related list values.
- [Translating User Interface](https://help.sdocs.com/sdocs/advanced-template-logic/translations/translating-the-s-docs-user-interface-ui.md): Reference for UI translation methods, supported screens, language matching, and troubleshooting.


---

# 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/sdocs/advanced-template-logic.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.
