Formatting in document templates depends on your chosen template format. Mail Merge Templates support automatic formatting using built-in wrappers, while Tag Templates require formatting to be handled in the merge data.
Formatting in document templates depends on your chosen template format. Mail Merge Templates support automatic formatting using built-in wrappers, while Tag Templates require formatting to be handled in the document template.
When generating documents in ScopeStack, formatting values—such as displaying 12345.67 as $12,345.67—depends on both the template format and the data format version. This article outlines the differences between the two main template formats and how each handles formatting tasks like currency or date output.
Mail Merge Template (Legacy)
Mail Merge Templates using V2 merge data support built-in formatting wrappers such as:
-
.to_currency
-
.to_long_date
-
.to_short_date
-
.to_formatted_time
Example usage:
<< total_revenue.to_currency >>
This will format the value using the project’s configured currency. These wrappers are part of ScopeStack’s internal logic and are applied before the data is converted to JSON. This allows formatting to happen automatically in the document output.
This setup is ideal for users who want formatting handled with minimal effort and without manually transforming values in the data layer.
Tag Templates
Tag Templates use an industry-standard rendering engine and require all data to be provided in JSON format. Because of this, wrapper methods like .to_currency
are not available. Instead, formatting must be handled manually.
If you're using a Tag Template, you can format currency by using filters inside the template syntax to apply number formatting (e.g., rounding, decimal precision)
Example:
{ { currency.unit }}{{ hourly_rate*1 | toFixed:2 } }
Note that in the above example, we added a space after the first { and before the final } due to our help center interpreting this as code and not displaying it. In real applications, there should be no space between the {{ and its close tag.
In this example:
-
currency.unit
supplies the symbol (e.g.,$
) -
hourly_rate*1
forces conversion of a stringified number into a decimal -
toFixed:2
formats the result to two decimal places
You can explore the full list of available filters in the Docxtemplater built-in filters documentation.
This method offers flexibility but may require more setup and awareness of the data structure being passed into the template.
Why Formatting Works Differently
The difference comes down to when and how formatting is applied:
-
Mail Merge Templates (Legacy) apply formatting at the application level, before converting data to JSON.
-
Tag Templates rely solely on the structure and content of the JSON payload, so formatting must be handled before or during the template render process using available filters.
Both approaches are valid—your choice depends on the level of control you want and how your document needs to be structured.
Recommendations
-
Use Mail Merge Template (Legacy) if you want to take advantage of ScopeStack’s built-in wrappers for automatic formatting.
-
Use Tag Templates if you need more flexibility in layout and are comfortable defining formatting rules within the template or merge data.