$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.
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). - 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
ƒ() indicates a function.
Methods at a glance
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 withattachTo, specify the node ID as the second parameter.
Signature$wsOptions.get(name, nodeId)
Return valueThe 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
Example: global option:
intValue option.
Example: option bound to a configuration node:
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
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.nodeId field:
$wsAccount:addressFields$wsAsse:asseConfigs$wsCategories:fields,customFields$wsConfig:countries,payments,shippingMethods,shippingMethodGroups,currency,emails,listElements,redirects$wsForm:loadType/loadAllTypesand theirfields/loadField
$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 topayment.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.
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: syntax, types, value limits,
attachTo, and display in the Admin Interface. - $wsConfig: provides, among other things,
paymentsincludingnodeId. - Configuration via code: configuration directly in the template.
- Storefront API options: read the same option values via the Storefront API.
