> ## Documentation Index
> Fetch the complete documentation index at: https://dokumentation.websale.de/llms.txt
> Use this file to discover all available pages before exploring further.

# $wsOptions - Template options

> Read the values of template options in the frontend, globally or per configuration node.

With the `$wsOptions` module, you read the values of template options in the frontend. Template options are settings that are defined once in the template and can then be maintained in the Admin Interface without having to adjust the template again. This lets you switch display details (for example whether the icon of a payment method appears in the footer) without touching the template.

This page is about reading the option values. How options are defined (types, value limits, `attachTo`, display in the Admin Interface) is described in [Defining template options](https://dokumentation.websale.de/en/frontend/referenz/optionen.md).

***

## Basic concept

A template option always goes through the same process: define → maintain in the Admin Interface → read in the template.

* **Define:** The option is created in a template with the `{{ option … }}` statement (see [Defining template options](https://dokumentation.websale.de/en/frontend/referenz/optionen.md)).
* **Become available:** Defined options appear in the Admin Interface after the templates have been compiled successfully. If an option is removed from the templates again, it only disappears from the Admin Interface after the templates are compiled again.
* **Maintain:** The values are set in the Admin Interface. For options bound to configurations, they can differ per configuration node (see `attachTo`).
* **Read:** in the template via `$wsOptions.get(…)`.

***

## Module overview

**Example / excerpt of** `$wsOptions`

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{= $wsOptions | json }}
```

**JSON output**

```json theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{
  "get": "ƒ()"
}
```

Note: `ƒ()` indicates a function.

**Methods at a glance**

| **Method** | **Return type** | **Description** |
| - | - | - |
| `get()` | depends on the option type | Reads the value of a template option (globally or per configuration node). |

***

## Templates

Template options can be read in any template.

***

## Variables

No variables are available for `$wsOptions`. Access is only possible via the `get()` method.

***

## Methods

### \$wsOptions.get()

Returns the value of a template option maintained in the Admin Interface. Without a second parameter, a global option is read. For options bound to a configuration node with `attachTo`, specify the node ID as the second parameter.

**Signature**\
`$wsOptions.get(name, nodeId)`

**Return value**\
The maintained value of the option. The type corresponds to the option type defined in the definition (`String`, `Bool`, `Int`, `Float`, `Enum`).\
If the option has not yet been explicitly set in the Admin Interface, `null` is returned. Therefore, check the return value before using it (for example with `if`) so that the template does not unintentionally remain empty for an option that has not yet been maintained.

**Parameters**

| **Name** | **Type** | **Required** | **Description** |
| - | - | - | - |
| `name` | string | yes | Name of the option as defined in the template. |
| `nodeId` | string | no | ID of the configuration node. Only specify for `attachTo` options (see below). If omitted, the global value is read. |

**Example**: global option:

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{= $wsOptions.get("intValue") }}
```

Outputs the value of the `intValue` option.

**Example**: option bound to a configuration node:

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{= $wsOptions.get("attached", "payment.payment.bill") }}
```

Returns the value of the `attached` option for the payment method with the configuration node `payment.payment.bill` (for example "Prepayment"). The second parameter is required because the same option can be set differently per node for freely creatable configurations, such as one configuration per payment method (for example disabled for "Prepayment" and enabled for "Google Pay").

#### nodeId: the ID of the configuration node

> [!NOTE]
>
> Do not confuse the **configuration node ID** (`nodeId`) with the `id` field within a configuration. The `payment.payment` configuration, for example, contains its own `id` field (a "technical ID"). This field **cannot** be used as `nodeId`.

So that you have the correct node ID at hand, the following objects provide a `nodeId` field:

* [`$wsAccount`](https://dokumentation.websale.de/en/frontend/referenz/module/wsAccount): `addressFields`
* [`$wsAsse`](https://dokumentation.websale.de/en/frontend/referenz/module/wsasse): `asseConfigs`
* [`$wsCategories`](https://dokumentation.websale.de/en/frontend/referenz/module/wscategories): `fields`, `customFields`
* [`$wsConfig`](https://dokumentation.websale.de/en/frontend/referenz/module/wsconfig): `countries`, `payments`, `shippingMethods`, `shippingMethodGroups`, `currency`, `emails`, `listElements`, `redirects`
* [`$wsForm`](https://dokumentation.websale.de/en/frontend/referenz/module/wsform): `loadType` / `loadAllTypes` and their `fields` / `loadField`

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ foreach $payment in $wsConfig.payments }}
  {{= $wsOptions.get("attached", $payment.nodeId) }}
{{ /foreach }}
```

Here, `$payment.nodeId` returns the node ID of the respective payment method, which is passed directly as the second parameter.

***

## Actions

No actions are available for `$wsOptions`.

***

## Examples

### Showing or hiding payment methods in the footer per payment method

In this example, an option bound to `payment.payment` is defined that displays in the footer only the payment methods for which the option has been enabled in the Admin Interface. This lets you decide per payment method what is displayed without adjusting the template.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ option "methodLocationFooter" with
  {
    "type": "Bool",
    "attachTo": "payment.payment"
  }
}}

{{ foreach $method in $wsConfig.payments }}
  {{ if $wsOptions.get("methodLocationFooter", $method.nodeId) }}
    <p>{{= $method.name }}</p>
  {{ /if }}
{{ /foreach }}
```

**Result**\
Only the payment methods for which the "`methodLocationFooter`" option is enabled are displayed in the footer. Since this option is bound to `payment.payment`, it is read per payment method via its `nodeId`. If the option is not set for a payment method, `get()` returns the value `null` and the `if` branch is not executed.

***

## Further links

* [Defining template options](https://dokumentation.websale.de/en/frontend/referenz/optionen.md): syntax, types, value limits, `attachTo`, and display in the Admin Interface.
* [\$wsConfig](https://dokumentation.websale.de/en/frontend/referenz/module/wsconfig.md): provides, among other things, `payments` including `nodeId`.
* [Configuration via code](https://dokumentation.websale.de/en/frontend/die-basics/konfiguration-per-code.md): configuration directly in the template.
* [Storefront API options](https://dokumentation.websale.de/en/schnittstellen/storefront-api/storefront-api-optionen.md): read the same option values via the Storefront API.


## Related topics

- [API reference template options](https://dokumentation.websale.de/en/schnittstellen/admin-interface-api/api-referenz-template-optionen.md)
- [Display a category](https://dokumentation.websale.de/en/v8s/kategorien/kategorie-anzeigen.md)
- [Purchase vouchers for printing](https://dokumentation.websale.de/en/v8s/gutscheine-anbieten/kaufgutscheine-zum-ausdrucken.md)
- [Order quantity of a product](https://dokumentation.websale.de/en/v8s/produkte/bestellmenge-eines-produkts.md)
- [Options](https://dokumentation.websale.de/en/frontend/referenz/optionen.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.