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

# Templates

> The one syntax for a value filled in later: what a template is, where it appears, and the names it reads.

A value filled in later is written as a template: a string holding `{{ expression }}`. BlobHub has no other
placeholder syntax. The same templates fill a listener's target, a workflow component's object alias, the
`text.render_template` component and, at install, an app's manifests.

## What a template is

* **The language** is the platform's sandboxed Jinja. Expressions go in `{{ … }}`; where a string is text, statements
  (`{% … %}`) and comments (`{# … #}`) work too.
* **Every string leaf** of a JSON or YAML value in a templated place is a template. A string with no marker renders to
  itself.
* **A lone expression keeps its type.** A string that is exactly one `{{ … }}` yields the expression's own JSON value,
  so `"{{ inputs.config }}"` is the document, not its text. Anything else yields text.
* **One moment and one set of names per place.** Each place a template may appear says when it is rendered and which
  top-level names exist then. A name outside that set is refused when the document is saved, naming the set.
* **The platform renders**, in one sandboxed renderer, within its bounds. No client renders a template.
* **Literal braces** are written inside `{% raw %} … {% endraw %}`.

| Template | Yields |
| - | - |
| `"{{ inputs.config }}"` | The document given for `config`, as an object |
| `"{{ blobs.flows.id }}"` | The id of the installation's `flows` blob |
| `"Reports for {{ installation.alias }}"` | The text `Reports for reports` |
| `"{% raw %}{{ name }}{% endraw %}"` | The text `{{ name }}` |

## Places

| Place | Rendered | Names |
| - | - | - |
| A [listener's target](https://docs.blobhub.io/blob-types/workflow/workflows/listeners.md#templates): every string of its `invocation_target`, `description` and `receipt` | When it fires | `batch`, `event`, `listener`, `item`, `object` |
| A workflow component's [object alias](https://docs.blobhub.io/blob-types/workflow/workflows/component-data.md#alias-and-run-input), on `data.message` and `data.messages` | When the component is read or written | `execution` |
| The template of [`text.render_template`](https://docs.blobhub.io/blob-types/workflow/workflows/component-text#text-render_template) | When the component runs | Its input routes, and `blob`, `session`, `definition`, `execution` and `attributes` |
| An app's [`blob.yaml`](https://docs.blobhub.io/blob-types/app/blob-yaml) manifests, and its credentials' `body` in [`app.yaml`](https://docs.blobhub.io/blob-types/app/app-yaml#credentials) | At install | `inputs`, `blobs`, `accounts`, `installation` ([below](#install-time-names)) |

```mermaid theme={null}
flowchart LR
  ver["A version<br/>blob.yaml and<br/>the files it names"]
  inst["Install<br/>renders blob.yaml with<br/>inputs, blobs,<br/>accounts, installation"]
  blob["The installed blob<br/>its definitions<br/>copied as they are"]
  run["Run time<br/>a listener fires and<br/>renders its target with<br/>event, batch, item"]
  ver --> inst --> blob --> run
```

The names of the two moments are disjoint, so a template written for the wrong moment is refused instead of rendered:
a manifest naming `event` or `execution` is refused when the version is committed.

## Install-time names

| Name | Is |
| - | - |
| `inputs.<name>` | What the admin gave for the input `<name>` ([Inputs](https://docs.blobhub.io/blob-types/app/app-yaml.md#inputs)) |
| `blobs.<alias>.id`, `blobs.<alias>.alias` | A blob of this installation, by its folder under `blobs/`: its id, and its alias, as `reports-flows` |
| `accounts.<alias>.id` | An app account's user id ([Accounts](https://docs.blobhub.io/blob-types/app/app-yaml.md#accounts)) |
| `installation.alias`, `installation.org` | The installation: its alias, as `reports`, and its organization |

* **Only manifests render at install**, and in `app.yaml` only a credential's `body`. The files a manifest names, a
  definition's or an object's `file`, are copied as they are, so a listener's own `{{ event.… }}` inside a
  definition reaches run time untouched.
* **Blobs are applied in the order their templates need.** A blob that reads `blobs.flows` follows `flows`, so Field
  Reports' `schedules`, whose target is `"{{ blobs.flows.id }}"`, is applied after `flows`. Otherwise folders go in
  name order, and folders that read each other's blobs in a cycle are a problem.
* **A secret is read only by a credential's `body`.** A `body` reads `inputs`, `accounts` and `installation`, not
  `blobs`: an install writes credentials before it makes any blob. A secret read anywhere else, or `blobs` read in a
  `body`, is a problem at commit.
* **An optional input left out** skips the nearest list item whose template reads it: a credential, an object, a
  definition, a `limits` entry, or one module of an entry's `includes`. An item inside another skipped item goes
  with it, and the plan names only the outer one. The plan says so in a `skips …` line, one of
  `skips credential <alias>: <input> was not given`,
  `skips <list item> <alias> in blob <blob>: <input> was not given`,
  `skips limit <id> in blob <blob>: <input> was not given`,
  `skips a module of limit <id> in blob <blob>: <input> was not given`,
  `skips an item of <list item> <alias> in blob <blob>: <input> was not given` or
  `skips an item of <path> in blob <blob>: <input> was not given`. An item with a string `alias` is named by it,
  with its list's name minus a final `s` as `<list item>`. One without is named by the nearest aliased item around it,
  else by its path
  ([Lines](https://docs.blobhub.io/blob-types/installer/operations/plan.md#lines)).

## What is not a template

* **Where the CLI reads a value from.** `--input name=@file` and `--input name=env:VAR` are where
  `blobhub installer install` reads an input's value from, not a syntax inside any document.
* **A reference object.** `{org, blob, revision, session, definition}` names a thing; a template may fill one of its
  parts, as `"{{ blobs.flows.id }}"` fills a schedule target's `blob`.
* **A workflow's ports and connections**, which carry values between components.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.