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

# Templating and Functions

> Variable interpolation and 45 built-in template functions in Replay.

# Templating and Functions

Replay uses Handlebars-style `{{ var }}` syntax for variable interpolation, plus 45 built-in functions for data transformation.

## Variable Interpolation

Any string field in a step can reference state variables:

```yaml theme={null}
- name: dynamic-request
  type: http
  request:
    url: /users/{{ user_id }}
    headers:
      Authorization: Bearer {{ token }}
    body:
      name: "{{ user_name }}"
      email: "{{ user_email }}"
```

Variables are resolved at execution time from the current state bag.

### Nested Access

Access nested fields with dot notation:

```yaml theme={null}
name: "{{ config.http.base_url }}"
message: "Hello {{ user.profile.first_name }}"
```

### Environment Variables

Environment variables are loaded into the global scope at startup. Access them directly:

```yaml theme={null}
config:
  postgres:
    dsn: postgres://{{ POSTGRES_USER }}:{{ POSTGRES_PASSWORD }}@localhost:5433/mydb
```

## Built-in Functions

### String Functions

| Function     | Description             | Example                            | Result          |
| ------------ | ----------------------- | ---------------------------------- | --------------- |
| `upper`      | Convert to uppercase    | `{{upper "hello"}}`                | `HELLO`         |
| `lower`      | Convert to lowercase    | `{{lower "HELLO"}}`                | `hello`         |
| `upperFirst` | Capitalize first letter | `{{upperFirst "hello"}}`           | `Hello`         |
| `lowerFirst` | Lowercase first letter  | `{{lowerFirst "Hello"}}`           | `hello`         |
| `trim`       | Trim whitespace         | `{{trim "  hi  "}}`                | `hi`            |
| `replace`    | Replace all occurrences | `{{replace "a-b-c" "-" "."}}`      | `a.b.c`         |
| `contains`   | Check substring         | `{{contains "hello" "ell"}}`       | `true`          |
| `startsWith` | Check prefix            | `{{startsWith "hello" "he"}}`      | `true`          |
| `endsWith`   | Check suffix            | `{{endsWith "hello" "lo"}}`        | `true`          |
| `split`      | Split string            | `{{split "a,b,c" ","}}`            | `["a","b","c"]` |
| `join`       | Join array              | `{{join (split "a,b" ",") "-"}}`   | `a-b`           |
| `truncate`   | Truncate with ellipsis  | `{{truncate "hello world" 8}}`     | `hello...`      |
| `padLeft`    | Pad left                | `{{padLeft "42" 5 "0"}}`           | `00042`         |
| `padRight`   | Pad right               | `{{padRight "42" 5 "."}}`          | `42...`         |
| `repeat`     | Repeat string           | `{{repeat "ab" 3}}`                | `ababab`        |
| `regexMatch` | Regex test              | `{{regexMatch "^\\d+$" "123"}}`    | `true`          |
| `regexFind`  | Regex find first        | `{{regexFind "\\d+" "abc123def"}}` | `123`           |

### Math Functions

| Function | Description    | Example         | Result  |
| -------- | -------------- | --------------- | ------- |
| `add`    | Addition       | `{{add 5 3}}`   | `8`     |
| `sub`    | Subtraction    | `{{sub 10 4}}`  | `6`     |
| `mul`    | Multiplication | `{{mul 3 4}}`   | `12`    |
| `div`    | Division       | `{{div 10 3}}`  | `3.333` |
| `mod`    | Modulo         | `{{mod 10 3}}`  | `1`     |
| `min`    | Minimum        | `{{min 5 3}}`   | `3`     |
| `max`    | Maximum        | `{{max 5 3}}`   | `5`     |
| `round`  | Round          | `{{round 3.7}}` | `4`     |
| `abs`    | Absolute value | `{{abs -5}}`    | `5`     |
| `ceil`   | Ceiling        | `{{ceil 3.2}}`  | `4`     |
| `floor`  | Floor          | `{{floor 3.8}}` | `3`     |

### Date Functions

| Function     | Description                | Example                                                     | Result                 |
| ------------ | -------------------------- | ----------------------------------------------------------- | ---------------------- |
| `now`        | Current UTC time (RFC3339) | `{{now}}`                                                   | `2026-06-03T12:00:00Z` |
| `nowUnix`    | Current Unix timestamp     | `{{nowUnix}}`                                               | `1759507200`           |
| `addMinutes` | Add minutes                | `{{addMinutes "2026-01-01T00:00:00Z" 30}}`                  | `2026-01-01T00:30:00Z` |
| `addHours`   | Add hours                  | `{{addHours "2026-01-01T00:00:00Z" 2}}`                     | `2026-01-01T02:00:00Z` |
| `addDays`    | Add days                   | `{{addDays "2026-01-01T00:00:00Z" 7}}`                      | `2026-01-08T00:00:00Z` |
| `formatDate` | Format date                | `{{formatDate "2026-01-01T00:00:00Z" "2006-01-02"}}`        | `2026-01-01`           |
| `parseDate`  | Parse date string          | `{{parseDate "2026-01-01" "2006-01-02"}}`                   | `2026-01-01T00:00:00Z` |
| `dateSub`    | Date difference (seconds)  | `{{dateSub "2026-01-02T00:00:00Z" "2026-01-01T00:00:00Z"}}` | `86400`                |

### JSON Functions

| Function        | Description                              |
| --------------- | ---------------------------------------- |
| `jsonStringify` | Convert value to JSON string             |
| `jsonParse`     | Parse JSON string to value               |
| `jsonPick`      | Extract nested value from object by path |
| `jsonKeys`      | Get object keys                          |
| `jsonValues`    | Get object values                        |
| `object`        | Build object from key-value pairs        |
| `merge`         | Merge two objects                        |

### Type Conversion Functions

| Function   | Description                        |
| ---------- | ---------------------------------- |
| `toInt`    | Convert to integer                 |
| `toFloat`  | Convert to float                   |
| `toString` | Convert to string                  |
| `len`      | Length of string, array, or object |

## Combining Functions

Functions can be nested:

```yaml theme={null}
message: "{{ upper (trim user_name) }}"
message: "{{ add (toInt count) 1 }}"
message: "{{ join (split tags ",") ", " }}"
```

## What's Next?

* Deep-dive into [working with JSON](/replay/guides/working-with-json) — extraction and assertions
* Integrate with [CI/CD pipelines](/replay/guides/ci-cd-integration)
