# Twig variables & examples

In the Twig editors (line items table and summary) the usual variables of the Shopware document templates are available. This page summarizes the most important ones.

## Availability per editor

| Variable          | Line items table |     Summary     |
| ----------------- | :--------------: | :-------------: |
| `order`           |         ✅        |        ✅        |
| `lineItems`       |   – (via loop)   |        ✅        |
| `lineItem`        | ✅ (per position) |        –        |
| `config`          |         ✅        |        –        |
| `hueRenderPhase`  |         ✅        |        –        |
| `currencyIsoCode` |         ✅        | set it yourself |
| `languageId`      |         ✅        |        –        |
| `billingAddress`  |         ✅        |        –        |

> The summary is rendered server-side and only receives `order` and `lineItems`. Set helper variables such as `currencyIsoCode` yourself there, e.g. `{% set currencyIsoCode = order.currency.isoCode %}`.

## Order (`order`)

| Expression                                              | Description                    |
| ------------------------------------------------------- | ------------------------------ |
| `order.orderNumber`                                     | Order number                   |
| `order.amountNet`                                       | Net total of the order         |
| `order.amountTotal`                                     | Gross total of the order       |
| `order.price.totalPrice`                                | Grand total                    |
| `order.price.rawTotal`                                  | Raw total (before rounding)    |
| `order.price.calculatedTaxes.sortByTax`                 | Taxes, sorted by tax rate      |
| `order.price.taxStatus`                                 | `gross` or `net`               |
| `order.shippingTotal`                                   | Shipping costs                 |
| `order.currency.isoCode`                                | Currency ISO code (e.g. `EUR`) |
| `order.deliveries.first.shippingMethod.translated.name` | Name of the shipping method    |
| `order.deliveries.first.getShippingOrderAddress`        | Delivery address               |
| `order.totalRounding`, `order.itemRounding`             | Rounding settings              |

## Position (`lineItem`)

| Expression                       | Description                             |
| -------------------------------- | --------------------------------------- |
| `lineItem.label`                 | Label                                   |
| `lineItem.quantity`              | Quantity                                |
| `lineItem.unitPrice`             | Unit price                              |
| `lineItem.totalPrice`            | Total price of the position             |
| `lineItem.payload.productNumber` | Product number                          |
| `lineItem.payload.options`       | Variant options (`group` / `option`)    |
| `lineItem.payload.features`      | Product features (e.g. reference price) |
| `lineItem.price.taxRules`        | Tax rates of the position               |

## Configuration (`config`)

| Expression                             | Description                        |
| -------------------------------------- | ---------------------------------- |
| `config.displayLineItems`              | Display positions?                 |
| `config.displayPrices`                 | Display prices?                    |
| `config.displayLineItemPosition`       | Display position number?           |
| `config.displayAdditionalNoteDelivery` | Additional delivery note           |
| `config.deliveryCountries`             | Delivery countries (IDs)           |
| `config.fileType`                      | File type of the rendered document |

## Useful filters

| Filter             | Description                                |
| ------------------ | ------------------------------------------ |
| \`{{ value         | currency(currencyIsoCode, languageId) }}\` |
| \`{{ value         | sw\_sanitize }}\`                          |
| \`{{ 'snippet.key' | trans }}\`                                 |

## Example: output the variant options of a position

```twig
{% if lineItem.payload.options|length >= 1 %}
    <br/>
    {% for option in lineItem.payload.options %}
        {{ option.group|sw_sanitize(null, true) }}: {{ option.option|sw_sanitize(null, true) }}
        {% if lineItem.payload.options|last != option %} {{ " | " }} {% endif %}
    {% endfor %}
{% endif %}
```

## Example: output the tax rates of a position

```twig
{% for tax in lineItem.price.taxRules %}
    {{ tax.taxRate }} %{% if loop.last %}{% else %}<br>{% endif %}
{% endfor %}
```

> **Tip:** Since the bundled default templates match Shopware's standard layout exactly, they are the best reference for available variables and their usage. Load the default template and work your way forward from there.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hubyte.de/pdf-dokumenten-template-bearbeiten/english-documentation/twig-variablen.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
