> ## 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.

# Data types

> Reference for WEBSALE template data types: strings, numbers, booleans, lists and maps used throughout variables, expressions and actions.

The following base data types are distinguished:

## String

A string is a character sequence, i.e., a sequence of characters (e.g., letters, digits, special characters, and control characters). Strings must always be written between two single or double quotes.

|                                    |                               |
| ---------------------------------- | ----------------------------- |
| `"Value1, Value2, Value3, Value4"` | String                        |
| `'Value1, Value2, Value3, Value4'` | String                        |
| `Value1, Value2, Value3, Value4`   | not a string (quotes missing) |

## Concatenation

With the `+` operator, it is possible to combine multiple strings.

In this example, we create variables for a greeting and put them together.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ var $greeting = "Welcome " }}
{{ var $customer = "new customer"}}
{{ var $genericGreeting= $greeting + $customer}} 
{{= $genericGreeting}} // Welcome new customer
```

Only strings can be concatenated. Nevertheless, it is possible to convert other variables into a string in order to concatenate them with a string.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ var $quantity = 1}}
{{ var $text = "Quantity: " + string($quantity) + "!" }}
{{= $text}} // Quantity: 1!
```

Other base types can be converted to string:

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
Boolean: {{= string(true) }} // "true"
Integer: {{= string(1) }} // "1"
Float: {{= string(1.1) }} // "1.1"
```

## Integer

Integers are whole numbers (numbers without decimal places).

|         |                                         |
| ------- | --------------------------------------- |
| `10`    | Integer                                 |
| `20.00` | not an integer (decimal places present) |

## Float

Floats are floating-point numbers with a **period** as the decimal separator.

|         |                                                          |
| ------- | -------------------------------------------------------- |
| `10.25` | Float                                                    |
| `10,25` | not a float (invalid syntax: comma as decimal separator) |

### Converting to float

Other base types can be converted to float:

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
String: {{= float("1.1")}} // 1.1
Integer: {{= float(1) }} // 1.0
Boolean: {{= float(true) }} // 1.0
```

## Boolean/Bool (true/false)

A bool is a truth value and can only be *true* or *false*.

|          |                                          |
| -------- | ---------------------------------------- |
| `true`   | truth value true                         |
| `false`  | truth value false                        |
| `"true"` | not a truth value (wrong syntax: string) |

Boolean values are mostly produced in combination with [comparison operators](/en/frontend/referenz/operatoren). For example, when comparing one value with another, the result is either true or false.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ if $quantity == 1 }}
    Displayed when the value of the variable $quantity equals 1.
{{ /if }}
```

### truthy and falsy

Not only values of the data type bool contain a truth value. Objects of all other data types also have a value property referred to as *truthy* or *falsy*. In the context of logical operators and branching, it is important to know when a value is considered true or false.

Here is a list of all values that are *falsy* and are therefore treated as *false*:

▪ *null*, the value of the Null data type

▪ *false*

▪ the number 0 (*Integer*) or 0.0 (*Float*)

▪ an empty *string " "*

▪ an empty *list \[ ]*

▪ an empty *map* { }

All other values are treated as *truthy*.

### Converting to boolean

Other base types can be converted to boolean:

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
String: {{= bool(" ")}} // true
String: {{= bool("")}} // false
Integer: {{= bool(1) }} // true
Integer: {{= bool(0) }} // false
Float: {{= bool(1.0) }} // true
Float: {{= bool(0.0) }} // false
```

## List

A list is a series of values, comma-separated and enclosed in square brackets. An empty list is written with square brackets containing nothing.

|             |             |
| ----------- | ----------- |
| `[1, 2, 3]` | filled list |
| `[ ]`       | empty list  |

The spaces between the values are optional.

## Distinct

If a list contains multiple entries that are identical, this function can be used to remove all duplicate entries.

**Arguments**

`list` - list to be processed

`key` - (optional) map key to be used for comparison with other maps.

**Example**

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ var $list = [ 1, 2, 3, 4, 3, 2, 5, 6, 1 ] }}
{{= distinct($list) }} // Result: [ 1, 2, 3, 4, 5, 6 ]
{{ $list = [ "a", 1, "b", true, 2, "a", true, true, {"x": 1, "y": 1}, {"x": 1, "y": 2} ] }}
{{= distinct($list) }} // Result: [ "a", 1, "b", true, 2, , {"x": 1, "y": 1}, {"x": 1, "y": 2} ]
```

For objects, you can specify a key to define which field should be used for comparison.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ var $list = [ 1, {"x": 1, "y": 1}, {"x": 1, "y": 2}, {"x": 2, "y": 2} ] }}
{{= $list | distinct("x") }} // Result: [ 1, {"x": 1, "y": 1}, {"x": 2, "y": 2} ]

similar notation without pipe:
{{= distinct($list, "x") }}
```

## Merge

Two lists can be merged with each other.

Additional information: in addition to using a function, the `+` operator (`$list1 + $list2`) can also be used.

**Arguments**

`target` - list to be used as the base for the merge

`source` - list with which the `target` should be extended

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ var $list1 = [ 1, 2, 3 ] }}
{{ var $list2 = [ 3, 4, 5] }}
{{ var $list3 = merge($list1, $list2) }}
{{= $list3 }} // Result: [1, 2, 3, 3, 4, 5]
```

## Map

A map is a list of key-value pairs written inside curly braces. The key and its value are separated by a colon. The individual key-value pairs are separated by commas. An empty map is written with curly braces containing nothing.

|                                                              |                            |
| ------------------------------------------------------------ | -------------------------- |
| `{ name: "Shirt", price: "12.95", image: "shirt-blue.jpg" }` | filled map                 |
| `{ "404": "Not found", "301": "Moved Permanently" }`         | filled map                 |
| `{ "Name, Description , Price, Additional info" }`           | not a map (invalid syntax) |
| `{ }`                                                        | empty map                  |

If a key contains characters other than digits (0-9), letters (a-z, A-Z), or underscores (\_) or begins with a digit/underscore, it must be specified as a string in quotes.

When outputting maps, the order of the individual key-value pairs is not preserved.

### **Merge**

Two maps can be merged with each other. With maps, when content differs, the content of the second entry is used. Nested maps can also be taken into account.

**Arguments**

`target` - map to be used as the base for the merge

`source` - map with which the `target` should be extended

`deep` - optional flag indicating whether the nesting of maps should be taken into account (default: `false`)

Example - merging two maps.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ var $map1 = { "a": 1, "b": 2, "c": { "x": 10, "y": 11 } } }}
{{ var $map2 = { "a": 2, "c": { "z": 12 }, "d": true } }}
{{ var $map3 = merge($map1, $map2) }}
{{= $map3 }}  // Result: { "a": 2, "b": 2, "c":{ "z": 12 }, "d": true }
```

Example - deep merge of two maps:

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ var $map1 = { "a": 1, "b": 2, "c": { "x": 10, "y": 11 } } }}
{{ var $map2 = { "a": 2, "c": { "z": 12 }, "d": true } }}
{{ var $map3 = merge($map1, $map2, true) }}
{{= $map3 }}  // Result: { "a": 2, "b": 2, "c":{ "x": 10, "y": 11, "z": 12 }, "d": true }
```
