Timplit Tutorial
Let's discover how to get started with Timplit's delightful document generation.
Contact [email protected] for support.
Introduction
A common pain point in many organizations is dynamically rendering documents. Think invoices, terms of service, and account statements. These chores suck up valuable developer time that could be put to better use building your core business. Timplit erases this pain, providing a ready made, delightful, dynamic document generation experience.
Templates are created using word processing software that you are already familiar with. Anyone who has used Microsoft Word, or the open source alternative Libre Office, is capable of quickly creating their first template.
These well known, feature rich editors can be used to format, style, and structure any kind of complex document. Special Timplit placeholders are used within the document to control the positioning and behavior of dynamic content. The format, style, and structure of the document created within Microsoft Word, or Libre Office, will flow through to the final rendered document.
Create a Template
Let's walk through creating your first template.
Global Parameters
The simplest Timplit placeholder is a single variable. It looks like this.
{{ FIRST_NAME }}
When rendering a template, dynamic data is provided as an identifier/value pair, known as a Variable.
{
"globalParameters": [
{
"identifier": "FIRST_NAME",
"value": "Alice"
},
]
}
With this example every instance of {{ FIRST_NAME }} within the template would be replaced with the string Alice. The style of the placeholder {{ FIRST_NAME }} in the template would be reflected in the rendered document. For example, if {{ FIRST_NAME }} was styled with an 18pt red font in the template file (docx, odt), the rendered text Alice would display as an 18pt red font.
Let's take a look at adding a last name global parameter.
{
"globalParameters": [
{
"identifier": "FIRST_NAME",
"value": "Alice"
},
{
"identifier": "LAST_NAME",
"value": "Cooper"
},
]
}
You can specify any number of global parameters, with any identifier you please. Although, it's good practice to use the same format for all of your identifiers to maintain consistency and ease of use, such as all caps, using camel_case, e.g. FIRST_NAME.
Conditionals
Sometimes we want to selectively render a section in a document depending on some condition being met. Timplit supports this common use case using a simple conditional placeholder.
{{ IF SHOW_SECTION_1 == “true” }}
This is the part of the document we want to selectively render.
{{ ENDIF }}
If the global parameter SHOW_SECTION_1 equals true the text This is the part of the document we want to selectively render. will appear in the rendered document.
When rendering a document, the conditional parameters are provided in the global parameters list.
{
"globalParameters": [
{
"identifier": "FIRST_NAME",
"value": "Alice"
},
{
"identifier": "SHOW_SECTION_1",
"value": "true"
},
]
}
Lists & Repeated Data
We commonly need to render a list of data objects in our documents, and Timplit supports this too! Data lists are managed using the built in table functionality in word processors.
As an example, let's imagine we want to display a list of products a user has purchased.
| Product Name | Product Price | Purchased At |
|---|---|---|
| {{ LIST products }}{{ products.NAME }} | {{ products.PRICE }} | {{ products.PURCHASED_AT }} |
{{ LIST products }} is the Timplit placeholder. In this case it instructs Timplit to parse a list with identifier products and insert it into the table. The other Timplit placeholders {{ products.NAME }}, {{ products.PRICE }}, and {{ products.PURCHASED_AT }}, identify the variables to be inserted for each entry in the products list.
The JSON request would look like this.
{
"tables": [
{
"identifier": "products",
"rows": [
{
"variables": [
{
"identifier": "NAME",
"value": "Juice Blender"
},
{
"identifier": "PRICE",
"value": "$49.99"
},
{
"identifier": "PURCHASED_AT",
"value": "12-2-2024 10:30 AM MST"
}
]
},
{
"variables": [
{
"identifier": "NAME",
"value": "Bowling Ball"
},
{
"identifier": "PRICE",
"value": "$32.99"
},
{
"identifier": "PURCHASED_AT",
"value": "12-15-2024 09:18 AM MST"
}
]
}
]
},
]
}