go-typst/examples/passing-values
David Vogel 9268a6691e Rework passing-values example
This changes the example to use the template pattern; we now have a single Typst file containing a template function.
Instead of loading and rendering the template, we will now generate temporary Typst markup that will import the template function and call it with custom data.

This also means that it's pretty easy to test, preview and debug the template.typ outside of go-typst.
All that is needed is another Typst file which will call the template with mock data.

Also, we now use Compile instead of CompileWithVariables and inject encoded Go values into our temporary markup.
2025-02-27 16:07:34 +01:00
..
main_test.go Rework passing-values example 2025-02-27 16:07:34 +01:00
main.go Rework passing-values example 2025-02-27 16:07:34 +01:00
output.pdf Rework passing-values example 2025-02-27 16:07:34 +01:00
README.md Rework passing-values example 2025-02-27 16:07:34 +01:00
template-preview.typ Rework passing-values example 2025-02-27 16:07:34 +01:00
template.typ Rework passing-values example 2025-02-27 16:07:34 +01:00

Passing values example

This example demonstrates how to pass values to Typst, which can be useful in rendering custom documents such as reports, invoices, and more.

How it works

This example follows the template pattern described in the Typst documentation. Here is a short overview of the files:

  • template.typ defines a Typst template function that constructs a document based on parameters.
  • main.go shows how to convert/encode Go values into Typst markup, and how to call/render the template with these converted values.
  • template-preview.typ also invokes the template while providing mock data. This is useful when you want to preview, update or debug the template.