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

# Jinja Templates: Wiring Data Between Workflow Blocks

> Use Jinja templates to pull workflow state, block outputs, and environment variables into any text field in a Scout workflow block.

Jinja templates enable dynamic inputs inside workflow blocks, pulling in state, outputs, environment variables, or computed values wherever a text field is accepted. They are the core mechanism for passing data between blocks — anywhere you can type text in a block's configuration, you can reference values from elsewhere in the workflow.

## Core Syntax

Jinja has two delimiters:

* `{{ ... }}` for **expressions** — evaluated and rendered into the field.
* `{% ... %}` for **control flow** — conditionals and loops that shape the output.

```jinja theme={null}
{{ inputs.user_message }}
{{ summarize_block.output }}
{% if inputs.priority == "high" %}urgent{% else %}normal{% endif %}
```

## Variable References

Scout provides three namespaces in every template:

| Namespace           | What it references                           |
| ------------------- | -------------------------------------------- |
| `inputs.field_name` | Fields defined on the workflow's Input block |
| `block_id.output`   | Output produced by a prior block             |
| `_env.VAR_NAME`     | Environment variables for secrets and config |

Nested fields use chained dot notation:

```jinja theme={null}
{{ fetch_user.output.email }}
```

## Common Use Cases

### Build a prompt with workflow state

Assemble an Agent prompt from the original question and retrieved context:

```jinja theme={null}
You are a helpful assistant.
The user asked: {{ inputs.question }}
Relevant context from the knowledge base: {{ retrieval_block.output }}
Answer based only on the context above.
```

### Build an API payload dynamically

Inject workflow values into a JSON body for an Action block:

```json theme={null}
{
  "user_id": "{{ inputs.user_id }}",
  "action": "{{ inputs.action }}",
  "timestamp": "{{ datetime.now(timezone.utc).isoformat() }}"
}
```

### Conditional messaging

Change the message based on workflow state:

```jinja theme={null}
{% if inputs.priority == "high" %}
Urgent: {{ inputs.message }}
{% else %}
FYI: {{ inputs.message }}
{% endif %}
```

## Date and Time

Use `__exp_global` for ready-made date strings, or reach for `datetime` directly when you need custom formatting:

```jinja theme={null}
{# Simple date strings #}
{{ __exp_global.current_date }}
{{ __exp_global.current_datetime }}
{{ __exp_global.current_time_utc }}

{# Custom formatting #}
{{ datetime.now(timezone.utc).isoformat() }}
{{ datetime.now(ZoneInfo("America/Los_Angeles")).strftime('%Y-%m-%d %I:%M %p') }}
```

The objects `datetime`, `timezone`, and `ZoneInfo` are available inside any template.

## Safe Templating Rules

<Tip>
  **Reference specific fields rather than whole objects.** `{{ block.output.name }}` is safer than `{{ block.output }}` because it fails loudly if the field is missing, instead of silently rendering a large object.
</Tip>

<Tip>
  **Keep logic out of templates.** Move any conditional longer than one line into a Condition block. Templates are for inserting values, not for branching business logic.
</Tip>

<Tip>
  **Test in Console first.** The Console shows rendered template output, so you catch bad references before they reach production.
</Tip>

<Warning>
  **Use `_env` for secrets and never hardcode credentials.** Reference API keys and tokens through `_env.VAR_NAME` so they stay out of your workflow definition.
</Warning>

## Next Steps

<CardGroup cols={2}>
  <Card title="Logic and State" icon="diagram-project" href="/workflows/logic-state">
    Understand how data flows between blocks through shared state.
  </Card>

  <Card title="Creating Workflows" icon="wrench" href="/workflows/creating-workflows">
    Build cleaner workflow architectures with a consistent pattern.
  </Card>

  <Card title="Blocks" icon="cubes" href="/workflows/blocks">
    See which block produces which output to reference in templates.
  </Card>

  <Card title="Running Workflows" icon="play" href="/workflows/running-workflows">
    Validate rendered template output in the Console before going live.
  </Card>
</CardGroup>
