Inputs
There are two types of inputs. A json
json
input contains structured data while a blob
blob
input passes bytes and optionally metadata to the template. For example, in an invoice the items and customer data could be a json
json
input and the company logo could be a blob
blob
input.
Template inputs are configured in the manifest file typst.toml
typst.toml
. The Oicana Typst package determines the current values of inputs.
Early Alpha
The Typst package is not (yet) published on Typst universe. You will have to install it locally.
- Download and install
the typship CLI
the typship CLI
- Clone the Oicana repository
- Run
typship install local
typship install local
inoicana/integrations/typst
oicana/integrations/typst
See the template dependencies section for more information.
Add the following to the top of your main.typ
main.typ
file to initialize the package:
This snippet gives the Oicana package access to the Typst project's files. We can now use the return values from calling setup
setup
in the rest of the template.
We will use a json
json
input to pass a name into the template. Add the following to the end of the typst.toml
typst.toml
file:
The value of this input is now available in the template as input.info
input.info
, where info
info
is the key of the input as defined in typst.toml
typst.toml
.
While we develop the template, the value of the input will be none
none
, because there is no Oicana integration setting a value for it. We can change that by defining a default
default
or development
development
value for the input.
Inputs can define two different fallback values, default
default
and development
development
. These fallback values differ in priority based on which mode the template is compiled in.
When compiling a template in development mode, input values have the priority
- Explicit input value (for example through an integration)
development
development
valuedefault
default
value
If you compile in production mode, the development
development
value is ignored:
- Explicit input value (for example through an integration)
default
default
value
While developing an Oicana template in a Typst editor, it will be compiled in development mode. It makes sense to define development
development
values for all required inputs of you template to have a functioning preview.
Let's extend our input with a development
development
value. First create an info.json
info.json
file in the template directory:
Then extend the input definition and set the development
development
value to be info.json
info.json
:
In our template we can now use input.info.name
input.info.name
and the preview will show "Chuck Norris".
With the input defined, we can update the packed template in the C# project. Run oicana pack
oicana pack
in the template directory and replace example-0.1.0.zip
example-0.1.0.zip
in the ASP.NET project with the new file.
Our compile
compile
endpoint is currently calling var stream = template.Compile([], [], CompilationOptions.Pdf());
var stream = template.Compile([], [], CompilationOptions.Pdf());
. This compiles the template without any inputs. The first empty array are the json
json
inputs and the second one the blob
blob
inputs.
Change the endpoint to set the name input we just defined.
Calling the endpoint now, will result in a PDF with the new name. Building on this minimal service, one could now start to accept inputs through the HTTP endpoint or add other inputs. Take a look at the open source ASP.NET example project on GitHub for a more complete showcase of the Oicana C# integration.