Basics
Syntax
An option is defined with theoption statement, a unique name, and the details after with:
stringValue of type String. This creates a text field in the Admin Interface. The value entered there is output in the template via $wsOptions.get("stringValue"). Each option has exactly one type, which determines the input form in the Admin Interface.
Uniqueness and lifecycle
Each option may only be defined once. If two options with the same name are defined in different templates or at different places in the same template, an error occurs. The defined options are available after the templates have been compiled successfully. If options are removed from the template, they only disappear from the Admin Interface after the templates are compiled again.Static values only
Only static values are possible in the definition. For example, you cannot use variables, operators, or functions. The following examples are therefore not possible:Display label and description
You can edit the display label and description of individual options in the Admin Interface or via the REST API. They are used for display only and have no other function.Option types
Each option has a type that determines the input form in the Admin Interface.String
Displayed as a text field in the Admin Interface. Example$wsOptions.get("freeShippingHint") then outputs exactly this text.
Bool
Displayed as an on/off switch in the Admin Interface. Suitable, for example, for switching a behavior or a display element on or off. Example$wsOptions.get("showTrustBadges") returns the value true, otherwise false. This is useful, for example, for showing or hiding the trust badges in the template.
Int
Expects an integer. Optionally, you can set value limits viamin and max.
Example
4, $wsOptions.get("productsPerRow") returns the value 4, for example to display four products per row.
Float
Expects a decimal number. As withInt, you can optionally specify min and max.
Example
4.5, $wsOptions.get("minRatingForBadge") returns this value, for example as the minimum rating from which a “Top rated” badge appears.
Enum
Allows selection from a predefined list. The allowed values are defined viavalues.
Example
grid, list, and slider in the Admin Interface. If an editor selects slider, $wsOptions.get("teaserLayout") returns the value slider, for example to display the teasers as a slider instead of a grid.
Binding options to configurations
WithattachTo, you bind an option to a configuration node, for example payment.payment for the payment methods:
- The setting can be edited directly in the respective configuration in the Admin Interface.
- For freely creatable configurations, such as one configuration per payment method, the setting can differ per node. For example, you can disable it for “Prepayment” and enable it for “Google Pay”. You read the value maintained this way in the template via $wsOptions.get(name, nodeId), where
nodeIdis the ID of the configuration node.
$wsOptions.get("showPaymentIconInFooter", "payment.payment.bill") returns true for the prepayment node and false for the Google Pay node. The footer icon therefore only appears for prepayment.
The configuration node ID is not the
id field within a configuration (the “technical ID”). The objects that provide the correct nodeId are listed under $wsOptions.Display in the Admin Interface
ViadisplayOptions.location, you define where in the clickable configuration interfaces of the Admin Interface the option appears:
location only works in combination with attachTo. Without a matching attachTo, the setting has no effect.
If
location is not specified, the option appears in a general “Template options” section of the respective configuration node.
