> For the complete documentation index, see [llms.txt](https://sevenval.gitbook.io/flat/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sevenval.gitbook.io/flat/develop/reference/templating/with.md).

# with

The template command `{{with _expression_}}` sets the context to the result of `expression` and executes the enclosed expressions or executes the corresponding `{{else}}` block if the expression evaluates to `null`.

Input:

```javascript
{
  "user": {
    "name": "alice",
  }
}
```

Template:

```markup
<template>
{
  {{with ./user}}
    "Name": {{ name }}
  {{else}}
    "Name": "unknown"
  {{end}}
}
</template>
```

Output:

```javascript
{
  "Name": "alice"
}
```

## Example: `with` and `json-doc()`

`{{with}}` is especially useful in conjunction with [`json-doc()`](/flat/develop/reference/functions/json-doc.md) to consolidate data from multiple sources using more compact expressions.

Input:

```javascript
{
  "location": "home"
}
```

Input `fit://request/request/body`:

```javascript
{
  "user": "fred",
  "pass": "wilma"
}
```

Template:

```markup
<template>
{
  "realm": {{ location }},
  {{with json-doc("fit://request/request/body") }}
    "user": {{ user }},
    "password": {{ pass }}
  {{end}}
}
</template>
```

Output:

```javascript
{
  "realm": "home",
  "user": "wilma",
  "password": "fred"
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sevenval.gitbook.io/flat/develop/reference/templating/with.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
