Document Template Syntax Guide
Overview
This page provides examples of syntax that can be used to merge data into document templates.
Document template merging is handled by the third-party product Aspose.Words. The complete official template syntax documentation is available here.
All functions and formatting strings listed on this page are case-sensitive.
Basic Objects
Data source objects can be inserted into a document template by either:
Double-clicking the object in the data source list to the left of the template
Entering the field tag into the template using the proper format
The following example substitutes “<<[siteOwnerName]>>” with the site owner name when the document is generated:
Site Owner: <<[siteOwnerName]>>When an object is selected from the data source list, it is added to the document at the current cursor location.
For more information on inserting data source objects into document templates, see the Viewing and Editing Document Templates page.
Signature Images
Signature images can be inserted into document templates either when the document is generated or finalized, using the signatureImage merge field in the currentUser data source.
For this merge field to work, the user’s signature image must be added to their user profile. Internal users can add signature images for other users on the User Details page, or add their own on the User Profile page. Support for signature images—and who can manage them—is configurable and available options may vary by implementation.
Inserting a Signature Image During Document Generation
To insert a signature image at the time of document generation:
Insert a textbox into the document at the location where the signature is to appear.
Add the following code block to the textbox:
<<image [IMAGETAG] -fitSizeLim>>Inserting the Current User’s Signature
To insert the signature image of the current user (the person generating the document), use:
<<image [currentUser.signatureImage] -fitSizeLim>>Inserting the Submission Processor’s Signature
To insert the signature image of the submission processor (available in the submission data source), use:
<<image [submissionStaffSignature] -fitSizeLim>>Inserting a Signature Image During Document Finalization
To insert a signature image at the time of document finalization:
Insert a textbox into the document at the location where the signature is to appear.
Add the following code block to the textbox:
[[FinalUserSignature]]This method adds the image to the PDF version of the document (but not the Word version) and can serve as an electronic signature by the person finalizing the document.
Site Images
A site image can be displayed in a document template when the template is generated.
To insert a site image at the time of document generation:
Insert a textbox into the document at the location where the image is to appear.
Add the following code block to the textbox:
<<image [siteImage] -fitSizeLim>>
QR Codes
A QR code can be generated in a document template by processing a custom text string and displaying it as a QR image. QR codes are inserted into documents when they are generated.
To insert a QR code into a document template:
Insert a textbox into the document at the location where the QR code is to appear.
Add the following code block to the textbox:
<<image [TemplateExtensions.StringToQRImageBytes("String to be converted into a QR code",150,150)]>>To create a complex text string, such as a URL, using data from the document, build the string using variables and pass it into the .StringToQRImageBytes() function. To define a variable, customize and insert the following at the beginning of the document template:
<<var [v_path = environmentSettings.applicationUrl + “site/permits/edit/” + id+”/detail”]>>Then, follow the steps above to insert a QR code. The code block in the text box should be in the following format:
<<image [TemplateExtensions.StringToQRImageBytes(v_path,150,150)]>>For more information on variables, see the Assigning Variables section below.
Loops
Loops can be used to find information related to a contact with a particular affiliation type or role code, or to return a list of violations associated with an evaluation. Returned values can be limited based on certain criteria and be added to the document body or tables.
Loops appear in bold in the data source list to the left of the document template during configuration and follow this format:
<<foreach [field in fields]>>Text or [Fields] here<</foreach>>For more information on using loops, see the Using Loops in Document Templates page.
Logical Operators
The following logical operators can be used to combine or modify Boolean (true/false) expressions, such as those used in <<if>> statements.
Operator | Meaning | Description | Example |
&& | and | Returns |
|
|| | or | Returns |
|
! | not | Returns |
|
Checking for Null Values
Occasionally, code in a document template may reference objects that don’t exist, resulting in an error. This can often be avoided by wrapping the code in an <<if>> statement that checks whether the object exists.
This type of <<if>> statement appears in the example code in the Breaking Out of a Loop section of the Using Loops in Document Templates page. In that example, the following statement is used to check whether any violations exist:
<<if[violations!=null]>>text to display if true<</if>>This can be read as “if violations is not equal to null” (in other words, “if a violation exists”). This ensures that the code within the <<if>> statement is only executed when violations are present.
A similar check is used for regulationReference:
<<if[regulationReference!=null]>>text to display if true<</if>>As with all <<if>> statements, a corresponding close tag (<</if>>) must be included.
Another way to check for null or empty fields is to use the .IsNullOrEmpty function, which checks whether the string is null or empty (""), or .IsNullOrWhiteSpace, which checks whether the string is null, empty (""), or consists only of white-space characters.
The following example uses .IsNullOrEmpty to evaluate regulationReference:
<<if[!string.IsNullOrEmpty(regulationReference)]>>text to display if true<</if>>This code ensures regulationReference exists and is not null or empty (""). If the condition returns true, the enclosed text is included in the generated document.
Displaying a Warning Message If Data Is Missing
A document template can also be configured to display a warning message when an expected object or data is missing. For example, the following code displays a warning if the organization for the agency contact (“Submission Staff Organization”) does not exist:
<<if[string.IsNullOrEmpty(submissionStaffOrg)]>>Submission Staff Organization is missing<<else>><<[submissionStaffOrg]>> Section<</if>>Preventing Blank Lines Caused by Missing Data
When checking for null values, it’s important to consider how missing data affects the layout of the document. For example, when displaying a site address, if the code that checks for siteAddress2 includes a line break, the address block may contain an unintended blank line between siteAddress1 and the fields below it (such as siteCity, siteState, and siteZip) when no data exists in siteAddress2.
To prevent this, ensure that any new line added by a null-check statement appears before the closing <</if>> tag. This is most easily done by enabling paragraph marks in Microsoft Word (Ctrl+Shift+8) and moving the paragraph mark so that it appears before the closing <</if>> tag.
Displaying Alternative Information If Data Is Missing
A document template can also be configured to display alternative information if data is missing.
For example, the following code checks if a site’s Owner Name field is blank; if so, it displays the Owner Organization Name instead. It also prevents a blank line from appearing if no data exists in siteOwnerAddr2, as explained in the previous section.
<<[siteOwnerName]>><<if[string.IsNullOrEmpty(siteOwnerName)]>> <<[siteOwnerOrgName]>><</if>> <<[siteOwnerAddr1]>><<if[!string.IsNullOrEmpty(siteOwnerAddr2)]>> <<[siteOwnerAddr2]>> <</if>> <<[siteOwnerCity]>>, <<[siteOwnerState]>> <<[siteOwnerZip]>>Formatting Objects
Aceoffix, the web-based control used to edit document templates, allows users to format dates, text, and numbers to better control the final document and maintain consistency. To format fields, use a colon after the object’s closing bracket, as in the following example:
<<[FieldName]:“Formatting String”>>Syntax for different formatting strings is provided in the following sections.
Formatting Dates and Times
Dates and times can be formatted in various ways. The following example shows a few different options:
<<[permitIssueDate]:“yyyy.MM.dd”>> <<[exampleDateWithTime]:”M/d/yyyy h:mm tt”>> <<[exampleDateWithTime]:”D”>>The following predefined formats have been configured to support common formats used in document templates.
Format | Example Output |
|---|---|
| 12/31/2024 |
| Tuesday, December 31, 2024 |
| Tuesday, December 31, 2024 1:45 PM |
| December 31 |
| December 2024 |
Custom formats can also be created by combining the following strings.
Format String | Description | Example Output |
|---|---|---|
| Day of the month | 31 |
| Day of the week (abbreviated) | Tue |
| Day of the week (full) | Tuesday |
| Month (numeric) | 12 |
| Month (name; abbreviated) | Dec |
| Month (name; full) | December |
| Two-digit year | 24 |
| Four-digit year | 2024 |
| Hour (24-hour clock) | 14 |
| Hour (12-hour clock) | 1 |
| Minutes | 45 |
| Seconds | 55 |
| Meridiem indicators | PM |
For example, the following syntax would produce a date with a full month name, day of the month, and four-digit year (such as “December 31, 2024”):
<<[DateTime.Now]:"MMMM dd, yyyy">>If a date isn't formatting correctly using the formats above, it may be stored as a different character type. To convert it to a valid DateTime format, use the Convert.ToDateTime() function, as in the following example:
<<[Convert.ToDateTime(receivableDate)]:"D">>
<<[Convert.ToDateTime(receivableDate).AddDays(30)]:”MMMM dd, yyyy”>>Formatting Text
Text can be formatted to display in uppercase, lowercase, title case (first letter of each word capitalized), or sentence case (only first letter capitalized).
Text formatting uses the following basic syntax:
<<[TextToFormat]:string>>The table below describes the available string options for configuring different text formats.
Format String | Description | Example Output |
|---|---|---|
| Lowercase | all lower case text |
| Uppercase | ALL UPPER CASE TEXT |
| Title case | Only First Letter Of Each Word |
| Sentence case | Only first letter of sentence |
For example, the following syntax displays the siteName in title case:
<<[siteName]:caps>>Another method to format text is to use the .ToUpper() or .ToLower() functions. The .ToUpper() function displays the value of a field in uppercase letters. For example, the following syntax would display John Doe’s name as “JOHN DOE”:
<<[permitPermitteeName.ToUpper()]>>An error occurs if a user attempts to call a method on a null field. See the Checking for Null Values section above to ensure a document template works in all situations. Note that using formatting strings does not cause an exception if the object’s value is null.
Formatting Numbers
Numbers can be formatted to display as currency (U.S. dollar), exponential notation, or percentages. Formatting options include adding thousands separators and rounding to a specified number of decimal places. When decimal places are specified, trailing zeros may be added.
Number formatting uses the following basic syntax:
<<[NumberToFormat]:"string">>The table below describes the available string options for configuring different number formats.
Format String | Description | Example String | Example Input and Output |
|---|---|---|---|
| Currency |
| 300129 → $300,129.00 |
| Exponential notation |
| 1052.0329112756 → 1.052033E+003 |
| Adds thousands separators and rounds to two decimal places |
| 1234.567 → 1,234.57 |
Adds thousands separators and rounds to one decimal place |
| 1234 → 1,234.0 | |
Adds thousands separators and rounds to three decimal places |
| 1234.56 → 1,234.560 | |
Adds thousands separator and rounds to the nearest whole number |
| 1234 → 1,234 | |
| Percentage rounded to two decimal places |
| 1 → 100.00% |
Percentage rounded to one decimal place |
| -0.39678 → -39.7% |
Numbers can also be formatted as ordered labels in various styles, including ordinal words (such as “first,” “second,” and “third”), alphabetic sequences (such as “A,” “B,” and “C”), or Roman numerals (such as “I,” “II,” and “III”).
Format String | Example String | Example Output |
|---|---|---|
|
| A, B, C |
|
| I, II, III |
|
| 1st, 2nd, 3rd |
|
| First, Second, Third |
|
| One, Two, Three |
|
| 8, 9, A, B, C, D, E, F, 10, 11 |
|
| - 1 -, - 2 -, - 3 - |
For example, the following syntax displays the current day of the month in ordinal format (such as “2nd day of January, 2024”):
<<[DateTime.Now.Day.ToString()]:ordinal>> day of <<[DateTime.Now]:"MMMM, yyyy">>Or, if using a date field, the following could be used:
<<[permitIssueDate.GetValueOrDefault().Day.ToString()]:ordinal>> day of <<[permitIssueDate]:"MMMM, yyyy">>When formatting numbers stored in a string format—such as data from a program component or a submission—the data type must be converted to numbers before formatting can be applied. For example, the following syntax displays a number stored in a string format as currency:
<<[Convert.ToDouble(fieldName)]:"C">>Formatting Text as a Hyperlink
The following syntax can be used to format text as a hyperlink:
<<link [url] [display text]>>For example, the following code creates a hyperlink using environmentSettings.productName as the display text and environmentSettings.applicationUrl as the link target:
Here is a hyperlink to <<link [environmentSettings.applicationUrl] [environmentSettings.productName]>>.The [display text] portion is optional—omitting it will display the active URL itself, as in the following example:
If you have any questions please visit the <<[environmentSettings.productName]>> support page at <<link [environmentSettings.contactUrl]>>.Building a Link Using Variables
If a specific link cannot be generated using available merge fields, it can often be constructed using variables.
For example, the following code builds a URL by combining a base application URL with additional path parts and an identifier, then creates a hyperlink using that URL with custom display text (“View Document Set”):
<<var [v_path = environmentSettings.applicationUrl + “admin/docset/edit/” + id + “/documents” ]>>
<<link [v_path] [“View Document Set”]>>For more information about variables, see the Accepted System Variables and Functions section below.
Accepted System Variables and Functions
Variables and functions provide dynamic content and logic within document templates, allowing data to be inserted, manipulated, or conditionally displayed. This section describes the accepted system variables and functions available for use.
Assigning Variables
Occasionally, it may be useful to assign a variable within a document template—for example, to print the variable only when its value changes or to filter records based on the variable. Assigning a variable involves storing a value in a named placeholder for later use within the template.
The following are examples of variable assignment:
<<var [current_yr = DateTime.Now.Year]>>
Current Year: <<[current_yr]>> (Example output: “Current Year: 2024”)
<<var [current_dt = DateTime.Now]>>
Current Date: <<[current_dt]>> (Example output: “Current Date: 12/31/2024 1:45:55 PM”)
Date and Time Functions
Some simple dynamic dates and times can be configured using prebuilt Microsoft add-ins, while others require coding.
Using the Microsoft Word Date Control
To include a date that updates automatically each time the document is created, saved, or printed, use the built-in Microsoft Word date control. To add the control:
Open the Insert tab on the Aceoffix Word ribbon.
Navigate to the the Text group and click the Quick Parts button.
Select the Field... option from the dropdown menu. This opens the Field dialog.
In the Field dialog, select the following values:
Categories: Date and Time
Field names: Create Date, SaveDate, or PrintDate
Date formats: Desired date format
Performing Date Calculations
To use DateTime methods or functions, enter .GetValueOrDefault(), followed by the method name. For example, the following syntax retrieves the year portion of a DateTime value:
<<[receivedDate.GetValueOrDefault().Year]To calculate the difference between two dates, use the .Subtract() function. For example, the following syntax returns the difference between permitExpireDate and permitIssueDate in days:
<<[permitExpireDate.GetValueOrDefault().Subtract(permitIssueDate.GetValueOrDefault()).ToString("%d")]>>Additional methods that can be used to calculate a date are described below. When using each method, int must be replaced with an integer value that specifies the number of units to add (or subtract, if negative) to the DateTime value.
Method | Description |
|---|---|
| Adds the specified number of days to the |
| Adds the specified number of hours to the |