go-typst/examples/passing-values/template.typ
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

37 lines
647 B
Plaintext

#let template(data, customText) = {
set page(paper: "a4")
[= Example]
customText
[== List of items]
show table.cell.where(y: 0): strong
set table(
stroke: (x, y) => if y == 0 {
(bottom: 0.7pt + black)
},
)
table(
columns: 5,
table.header(
[Name],
[Size],
[Example box],
[Created],
[Numbers],
),
..for value in data {
(
[#value.Name],
[#value.Size],
box(fill: black, width: 0.1mm * value.Size.X, height: 0.1mm * value.Size.Y),
value.Created.display(),
[#list(..for num in value.Numbers {([#num],)})],
)
}
)
}