Typst
| Template type (numeric) | Supports automatic variable detection |
|---|---|
| 2 | ❌ |
To utilize Typst templates, create a new template project directory, and edit the entrypoint file with the name main.typ to create the template. You may embed additional resources into the project directory if necessary.
For example:
.
├── main.typ
└── logo.png
Then, package the project directory as a .zip archive and upload it as a template file.
Text variables
Text template variables are provided using sys.inputs.
Image variables
Image template variables are provided as regular files under __impressum_images path.
For example, to access the logo image variable, you would utilize the following path: __impressum_images/logo.png.
To access __impressum_qrcode, you would utilize this path: __impressum_images/__impressum_qrcode.png.
Dynamic variables
Dynamic variables operate like regular Typst variables. Document Rails maps input JSON objects into Typst dictionaries automatically for eligible credential variables.
Dynamic variables are provided through sys.inputs, and have a priority over text variables if their names collide. To prevent name collision, use unique credential variable names for input credentials.
Fonts
By default, Document Rails includes some default fonts, but it is highly recommended to supply custom fonts for document rendering using font loading capabilities.
To provide custom fonts to Document Rails, add them as .ttf files to the fonts directory of your template archive.
Examples
import { createTemplate, TemplateType, TemplateVarType } from "@vaultie/document-rails";
const response = await createTemplate(
client,
accessToken,
organizationId,
{
// Select the Typst template type.
template_type: TemplateType.Typst,
// .zip archive containing the Typst template.
file: new Blob([await readFile("./template.zip")]),
// Template variables present within the uploaded file.
//
// For Typst templates, `template_vars` field is required.
template_vars: [
{ name: "first_name", type: TemplateVarType.String },
{ name: "last_name", type: TemplateVarType.String },
{ name: "profile_photo", type: TemplateVarType.Image },
]
}
);