> For the complete documentation index, see [llms.txt](https://docs.hubyte.de/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hubyte.de/artikel-konfigurator/english-documentation/ausgabe-bestellung-belege/email-template.md).

# Email template & variables

The fields filled in by the customer are stored in the **payload of each order line item** and are therefore available in Shopware's email templates. This lets you output the additional fields e.g. in the **order confirmation**.

You maintain email templates in the administration under **Settings > Email templates**. Inside the loop `{% for lineItem in order.lineItems %}` you have access to the variables described below.

## Available variables per order line item

Depending on the configuration, the plugin stores up to three additional entries in `lineItem.payload`:

| Variable                                  | Content                                                                                                                          |
| ----------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| `lineItem.payload.huebert_attributes`     | All filled-in fields **without** a separate price (text, number, date, selection, color, file …).                                |
| `lineItem.payload.attributes_with_prices` | Fields/options **with a surcharge** (only when "prices" are enabled).                                                            |
| `lineItem.payload.dependencies`           | Fields confirmed via a [dependency (checkbox)](/artikel-konfigurator/english-documentation/abhaengigkeiten.md), including price. |

### Structure of `huebert_attributes`

`huebert_attributes` is a list. Each entry is a collection of fields with the following properties:

| Property          | Meaning                                                                                                                                    |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| `attribute.name`  | Label of the field (field name).                                                                                                           |
| `attribute.value` | Entered or selected value. For a **media upload** this is the file URL, for the **color selection** an object with `colorName`/`hexColor`. |
| `attribute.order` | Order of the field (for sorting).                                                                                                          |
| `attribute.type`  | Field type (e.g. `text`, `number`, `dropdown`, `single-select`, `multi-select`).                                                           |
| `quantity`        | Special key holding the quantity (only relevant with separated quantity handling).                                                         |

### Structure of `attributes_with_prices`

A map of the form `optionName => { valueName => { price, quantity } }`:

| Property         | Meaning                           |
| ---------------- | --------------------------------- |
| `array.price`    | Surcharge of the selected option. |
| `array.quantity` | Quantity for the option.          |

## Template: output fields in the email

Insert the following block **inside** the line item loop of your email template (i.e. between `{% for lineItem in order.lineItems %}` and the corresponding `{% endfor %}`):

```twig
{% set currencyIsoCode = order.currency.isoCode %}

{# 1) Simple fields without a price #}
{% if lineItem.payload.huebert_attributes is defined and lineItem.payload.huebert_attributes %}
    {% for attributesList in lineItem.payload.huebert_attributes %}
        {% for key, attribute in attributesList|sort((a, b) => a.order <=> b.order) %}
            {% if key != 'quantity' and attribute.name is defined and attribute.value is defined %}
                <div>
                    <strong>{{ attribute.name|replace({'_': ' '}) }}:</strong>
                    {% if attribute.value.colorName is defined %}
                        {{ attribute.value.colorName }}
                    {% elseif 'http://' in attribute.value or 'https://' in attribute.value %}
                        <a href="{{ attribute.value }}">{{ attribute.value }}</a>
                    {% else %}
                        {{ attribute.value }}
                    {% endif %}
                </div>
            {% endif %}
        {% endfor %}
    {% endfor %}
{% endif %}

{# 2) Options with a surcharge #}
{% if lineItem.payload.attributes_with_prices is defined and lineItem.payload.attributes_with_prices %}
    {% for optionName, options in lineItem.payload.attributes_with_prices %}
        {% for name, array in options %}
            {% set price = array.price|number_format(2)|floatval * array.quantity %}
            <div>
                <strong>{{ optionName }}:</strong> {{ name }}
                ({{ array.quantity }} × {{ array.price|number_format(2)|floatval|currency(currencyIsoCode) }}
                = {{ price|currency(currencyIsoCode) }})
            </div>
        {% endfor %}
    {% endfor %}
{% endif %}
```

## Examples

### Output a single field only

If you want to output exactly **one** field by its name:

```twig
{% if lineItem.payload.huebert_attributes is defined %}
    {% for attributesList in lineItem.payload.huebert_attributes %}
        {% for key, attribute in attributesList %}
            {% if attribute.name == 'Engraving' %}
                Engraving: {{ attribute.value }}<br>
            {% endif %}
        {% endfor %}
    {% endfor %}
{% endif %}
```

### Output a media upload as a link

```twig
{% for attributesList in lineItem.payload.huebert_attributes %}
    {% for key, attribute in attributesList %}
        {% if attribute.value is not null and ('http://' in attribute.value or 'https://' in attribute.value) %}
            {{ attribute.name }}: <a href="{{ attribute.value }}">Download file</a><br>
        {% endif %}
    {% endfor %}
{% endfor %}
```

### Table row in the line item overview

Inside an existing line item table (`<table>`) you can output a separate row per field:

```twig
{% if lineItem.payload.huebert_attributes is defined %}
    {% for attributesList in lineItem.payload.huebert_attributes %}
        {% for key, attribute in attributesList|sort((a, b) => a.order <=> b.order) %}
            {% if key != 'quantity' and attribute.name is defined %}
                <tr>
                    <td></td>
                    <td><small><strong>{{ attribute.name|replace({'_': ' '}) }}:</strong> {{ attribute.value }}</small></td>
                    <td></td><td></td><td></td>
                </tr>
            {% endif %}
        {% endfor %}
    {% endfor %}
{% endif %}
```

> **Note:** The plugin already ships with adapted default mail texts. If you use your own template, simply copy the blocks above into your existing template. Make sure `currencyIsoCode` is defined (`{% set currencyIsoCode = order.currency.isoCode %}`) before using `|currency(...)`.

## Additional field for the shop operator

Independent of the customer's entries, the shop operator can add a custom entry to the order confirmation email per article (**General** tab on the article, **Hubyte Article Configurator** card). You define the corresponding label in the [plugin configuration](/artikel-konfigurator/english-documentation/plugin-konfiguration.md) under `konfiguratorAdminLabel`. More on this under [Output in order & documents](/artikel-konfigurator/english-documentation/ausgabe-bestellung-belege.md).
