# Use variables in a compliance template

Variables are the {{ placeholders }} PiGi swaps for real values when it renders a compliance document — the student's name, the instructor's licence number, the permit code, the signatures. Which variables are available depends entirely on the template's Type, and a template whose Type has no variable set renders a completely blank PDF.

Source: https://help.pigi.io/guides/compliance/documents/template-variables

## Quick answers

**How do I write a variable?**
As `{{ variable_name }}`. Spaces inside the braces are fine. Click a variable in the
**Context variables** panel to insert it rather than typing it — a typo renders as
empty text, not as an error.

**Why is my generated PDF completely blank in every field?**
Because the template's **Type** is not one PiGi resolves variables for. Only
**Indemnity**, **Permit**, **Contract** and **Medical** have a variable set. Any other
type resolves to nothing and every placeholder renders empty. The editor preview does
not fill values the same way, which is why a broken template can look perfect on screen.

**Which variables can every template use?**
The Shared group: `company_name`, `company_logo`, `company_caa_dto_number`,
`company_currency`, `provider_name`, `provider_logo`, `issue_date` and `current_year`.
PiGi also fills `provider_report_email`.

**Which variables does an Indemnity get?**
Shared, plus the Code group (`code`, `code_cycle_name`, `background_color`,
`expiry_date`, `manual_code`), Instructor, Student, Signing, and the Flying Site group
(`flying_site_name`, `flying_site_location`, `flying_site_region`,
`flying_site_country`, `flying_site_location_and_country`).

**Which variables does a Permit get?**
The same as an Indemnity minus the Flying Site group.

**Which variables does a Medical get?**
Shared, Instructor, Student and Signing. Medicals get no code and no flying site.

**Which variables does a Contract get?**
Shared plus the Contractor group, an expanded Instructor group, `school_name`,
`agreement_date`, the two-party Signing group (contractor and company signatures,
names, titles, places) and the Payment group (`instructor_payment_frequency`,
`instructor_payment_days`, `instructor_payment_dates`).

**How do I show a paragraph only when a value exists?**
Wrap it: `{% if witness_name %} … {% endif %}`. The condition must be a bare variable
name — the block is kept when the value is non-empty and dropped when it is empty.
Comparisons, filters and `{% else %}` are not supported.

**How do I put a comment in a template?**
Do not use `{# … #}` comments across more than one line — a multi-line comment of
that shape is printed into the finished document as literal text. Use
`{% comment %} … {% endcomment %}`, or keep the comment on a single line.

**Do signatures need an `<img>` tag?**
No. If you drop a bare `{{ student_signature }}` into the text, PiGi wraps it in an
image tag when it renders, so it comes out as the drawn signature rather than a long
URL. Writing `<img src="{{ student_signature }}">` yourself also works.

**Why is the instructor's licence number blank?**
PiGi prefers a licence the instructor has flagged for compliance documents, then the
most recent unexpired one, then the most recent licence of any state. If the pilot has
no licence record at all the field renders empty.

**Where does `background_color` come from?**
For a document with a code, from the code's purchasing cycle colour (falling back to
white). In the template editor the swatch you pick is substituted into the preview.

## What this is

Every compliance document is HTML with `{{ placeholders }}`. When the document is
issued, PiGi resolves a value for each placeholder from the student, the instructor,
the school, the provider, the code and the flying site, then renders the result to PDF.

The set of placeholders PiGi will resolve is fixed per template **Type**. That is the
single most important thing to know: choosing the Type is choosing the vocabulary.

## Steps

1. Open the template and set its **Type** first.
2. Open the **Context variables** panel on the right of the editor. It is grouped by
   Company, Provider, Dates, Student, Instructor, Signing, Code, Flying Site,
   Contractor, School and Payment depending on the Type, and the current Type is
   printed in the panel header.
3. Click a variable to insert it at your cursor.
4. Preview with the eye icon, then save.
5. Issue one real document and open the PDF before you rely on the template. The
   preview and the final PDF resolve values differently.

## Known limitations

- **The preview is not proof.** The editor preview renders your HTML but does not fill
  values the same way as the finished PDF. A template whose Type resolves nothing
  previews perfectly and prints blank.
- **Unknown variables render as empty text**, not as an error. There is no validation
  pass that tells you a name is wrong.
- **Unsupported template syntax is silently stripped.** `{% else %}`, comparisons and
  any other `{% … %}` tag are removed from the output rather than flagged.
- **Already-generated PDFs do not change** when you fix a template. Regenerate the
  document to pick up the corrected wording.

## Related

- [Create a compliance document template](document-templates.md)
- [Signed documents](signed-documents.md)
