---
url: /vouchers.md
---
# Gift Vouchers

A gift voucher template (Administration › Texty › Šablony › Voucher) is the PDF of a gift voucher:
the value, the code, the validity, a barcode, the shop's design. It is a full HTML document with a
`<style>` block in Twig, rendered to a PDF of the template's format, one PDF per voucher: in the
voucher's download in the administration and in the e-mail with a sold digital voucher. A shop can
have several, e.g. one printed onto pre-printed vouchers (only the value, the code and the validity,
placed in mm) and a full design for the e-mail; several designs go on several pages of one PDF.

## Variables

| Variable | Type | Description |
|---|---|---|
| `voucher` | [Voucher/GiftVoucher](/objects#voucher-giftvoucher) | The voucher: `code`, `name` (its discount template's), `validFrom`, `validTo`, `value`, `discount` |
| `shop` | [Shop](/objects#shop) | The shop the voucher is for: the domain it was bought on (in the e-mail), the main domain (in the administration's download and preview). `name`, `url`, `shortDomain`, `email`, `phone` |

* `{{ voucher.value }}`: the value with its currency (`1 500 Kč`); `{{ voucher.value.value }}` the
  number, `{{ voucher.value.currency }}` the currency code, `{{ voucher.value.formattedValue }}` the
  formatted number, `{{ voucher.value.currencySymbol }}` the symbol ([PriceValue](/objects#pricevalue)).
  A voucher's value is in the currency it was paid in: a voucher bought on a domain in euros shows `40 €`
  on a shop whose main currency is the Czech crown, so write the symbol with `{{ voucher.value }}` or
  `currencySymbol`, never by hand. Older vouchers, and codes generated by hand in the administration or
  through the API, are in the shop's main currency.
* `{{ voucher.discount }}`: what the voucher is worth as text: the value with its currency, or a percent code's
  percentage (`10%`). Use it in a template that is also downloaded for percent codes; `voucher.value` for a gift voucher.
* `{{ voucher.validFrom|date("d. m. Y") }}`, `{{ voucher.validTo|date("j. n. Y") }}`: the validity.
* `{{ voucher.code }}`: the code, `{{ voucher.name }}`: the name of the voucher's discount template.

The older variables `code`, `value`, `validFrom` and `validTo` exist only in the administration's
download and preview, not in the e-mail: use `voucher` (`value` is `voucher.discount`). Every shop's templates were
converted to `voucher` in 2026-11, except the few a conversion could not prove the same.

## Languages

A voucher template has a text per language of the shop, as every text template. A sold voucher's PDF is made in
the language of its order, its value in the currency it was paid in: a voucher bought on a Slovak domain in euros
is the Slovak text with `40 €`. A language other than the shop's default one *inherits* the default text until it
gets one of its own (Texty › Šablony › the template › the language's tab): until then a Slovak customer gets the
Czech text. Write the words in each language's text; the variables, the layout and the pictures stay the same unless
a language needs its own. The voucher studio edits and shows every language at once.

## Barcodes and QR codes

Write a barcode as a tag; it becomes an image before the PDF is made:

| Tag | Code |
|---|---|
| `<img-code128 src="{{ voucher.code }}" width="1" height="50"/>` | Code 128 (any text) |
| `<img-qr src="…" width="80">` | QR code (`width` in px) |

`width` is the width of one bar (default 2), `height` the bars' height in px (default 30).
`<img-ean13>` and `<img-codeI25>` take digits only. Size and place the image with CSS.

## Page and colours

The page is the template's format, width × height in mm (Formát on the template's page), without
margins; without a format it is A4. Make the design fill its page (`html, body { height: 100% }`;
`100vh` is not the page's height in the PDF), or place its parts in mm for a pre-printed voucher.
Another design on the next page: `break-after: page` after the first. Backgrounds and colours are
printed only with `-webkit-print-color-adjust: exact` (and `print-color-adjust: exact`), and only on an
element: the PDF leaves out a background of `html` or `body` (a colour and a picture alike, as the browser
moves it onto the page itself). Give the page a wrapper element that fills it (`.voucher { height: 100% }`
under `html, body { height: 100% }`) and put the background on that.

A picture that fills the page, or a box, and is cropped to it goes in as an `<img>` inside the element, which
crops it with `overflow: hidden`, never as `background-size: cover` or `object-fit: cover`. The PDF keeps a
picture as the JPEG it is only while the whole picture is drawn: a picture `cover` crops is stored uncompressed,
about nine times larger (312 KB became 2.9 MB in each voucher's PDF, 2026-11-09), and every e-mail with a
voucher carries that.

```css
.voucher { position: relative; height: 100%; overflow: hidden; }
.voucher > .photo { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 100%; height: auto; }
.voucher > .content { position: relative; }
```

`width: 100%; height: auto` when the picture is taller for its width than the element (a 3 : 2 photo on a 210 × 99 mm
voucher), `height: 100%; width: auto` when it is wider; a picture shown whole is a plain `<img>` with its size.

## What a voucher may use

In the voucher studio a voucher renders in a restricted environment, and before every render and
save the studio checks the text as written, every branch of it. A text the studio saves names
nothing but `voucher` and calls nothing but its getters and a date's `format`, so it does no more in
the administration's download and in the e-mail than in the studio:

* Variables: only `voucher`, `shop`, and names the template sets itself (`set`, `for`, `with {…}`, a macro's
  arguments). Not `code`, `value`, `validFrom`, `validTo` (use `voucher.…`), not `_context`, not
  `_self` (except calling the template's own macros: `_self.name(…)`), nothing else even behind
  `is defined`.
* Attributes: `voucher.code`, `voucher.name`, `voucher.value`, `voucher.discount`, `voucher.validFrom`, `voucher.validTo`;
  `shop.name`, `shop.url`, `shop.shortDomain`, `shop.email`, `shop.phone`;
  of the value `value`, `currency`, `formatted`, `formattedValue`, `currencySymbol`,
  `currencySymbolBefore`; a date only through `|date("…")` or `.format("…")` with a written format.
  Names written in the text, not computed.
* Tags `if`, `for`, `set`, `apply`, `with`, `verbatim`, `macro`, `autoescape` (no `import`,
  `include`); Twig's filters that format (`date`, `date_modify`, `number_format`, `format`,
  `replace`, `upper`, `lower`, `trim`, `slice`, `join`, `default`, `e`, `raw`, `nl2br`, …) but none
  that takes a function (`filter`, `map`, `reduce`, `sort`, `find`, `column`); the functions `date`,
  `range` (written bounds, at most 1000 apart), `cycle`, `max`, `min`, `random`; the tests
  `defined`, `empty`, `null`, `even`, `odd`, `iterable`, `divisible by`, `same as` (not `constant`).
* Output is escaped as HTML. An attribute that does not exist is an error with its line.

## What shops ask for

| Ask | How |
|---|---|
| The value large, the first thing to see | `{{ voucher.value }}` in its own element, `white-space: nowrap`, sized for the highest value the shop sells (`50 000 Kč`) |
| Value and currency set apart | `{{ voucher.value.formattedValue }}` and `{{ voucher.value.currencySymbol }}`; never write `Kč` or `€` by hand |
| A barcode the till scans | `<img-code128 src="{{ voucher.code }}" width="1" height="50"/>`, not narrowed by CSS: a long code needs its length (11 modules a character plus 35), with a quiet zone of white around it |
| A QR code to the shop | `<img-qr src="https://www.example.cz/" width="80">` with the shop's address written out |
| The shop's name and web | `{{ shop.name }}`, `{{ shop.shortDomain }}` (`{{ shop.url }}` for a QR code): the domain's own, so a voucher bought on the Slovak domain names the Slovak shop |
| The shop's logo | an `<img>` of the logo's address (Administrace › Nastavení › domain › logos), e.g. at the top, `max-height` in mm |
| A picture as the background | `<img class="photo" src="https://i00.eu/file/…">` in a wrapper element that fills the page and crops it (`overflow: hidden`, see Page and colours), never `background-size: cover` or `object-fit: cover`: the PDF then stores the picture uncompressed, nine times larger |
| Printing onto pre-printed cards | no background or colours, only the value, the code and the validity, each `position: absolute` in mm from the card's corner; try a print on paper against a card |
| Terms of use on the second page | `<div style="break-after: page">` around the first page, the terms after it |
| A different design per value | `{% if voucher.value.value >= 5000 %}…{% else %}…{% endif %}` |
| Validity written out | `platí do {{ voucher.validTo\|date("j. n. Y") }}`; from-to: `{{ voucher.validFrom\|date("j. n.") }} – {{ voucher.validTo\|date("j. n. Y") }}` |
| A voucher in another language | that language's tab of the template: its own text, the same variables |

A voucher is printed or sent as a PDF: check each of these on a high value, a long code and a long name, at the
template's format.

## Example

```twig
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <style>
        html, body { height: 100%; margin: 0; font-family: Arial, Helvetica, sans-serif; }
        body { -webkit-print-color-adjust: exact; print-color-adjust: exact; color: #1d2b3a; }
        /* the background on the page's wrapper: the PDF leaves out a background of html or body */
        .voucher { box-sizing: border-box; height: 100%; padding: 12mm; background: #f6f1e7; display: flex; flex-direction: column; justify-content: space-between; text-align: center; }
        .value { font-size: 18mm; font-weight: bold; white-space: nowrap; }
        .code { font-size: 6mm; letter-spacing: 0.5mm; white-space: nowrap; }
    </style>
</head>
<body>
    <div class="voucher">
        <div>{{ shop.name }}</div>
        <h1>Dárkový poukaz</h1>
        <div class="value">{{ voucher.value }}</div>
        <div>
            <div class="code">{{ voucher.code }}</div>
            <img-code128 src="{{ voucher.code }}" width="1" height="50"/>
        </div>
        <p>Platí do {{ voucher.validTo|date("j. n. Y") }}</p>
    </div>
</body>
</html>
```
