# Template

URL: /business/nouns/template · Id: `noun:template`

> A Template is reusable Content with variables, filled from Things in the graph and authored as MDX, rendering a Message, Document, or Page.

A Template is an inheritable [Startup](/business/nouns/startup) definition that a new Startup extends, overriding anything it inherits.

## Properties
| Property | Type | Required | Description |
| --- | --- | --- | --- |
| `body` | `text` | Yes | The MDX source with its variables. |

## Object
```json
{
  "$id": "https://api.sb/tutorloop.com/templates/template_1",
  "$type": "Template",
  "body": "Example body"
}
```

## Relationships
- <a id="rel-generates"></a>A Template **generates** many [Documents](/business/nouns/document): a Template fills its variables from the graph to generate a [Document](/business/nouns/document), such as a proposal or an invoice. `generates`, inverse [`generatedFrom`](/business/nouns/document#rel-generated-from).
- <a id="rel-places"></a>A Template **places** many [Components](/business/nouns/component): a Template places named [Components](/business/nouns/component), such as `Pricing`, and fills their props from records. `places`, inverse [`placedBy`](/business/nouns/component#rel-placed-by).
- <a id="rel-renders"></a>A Template **renders** many [Pages](/business/nouns/page): a Template fills one [Page](/business/nouns/page) per [Thing](/business/nouns/thing) or per member of a [Collection](/business/nouns/collection). `renders`, inverse [`renderedWith`](/business/nouns/page#rel-rendered-with).

## Verbs
| Verb | Description | Subject | Event | Class |
| --- | --- | --- | --- | --- |
| [Template.extend](/business/nouns/template/extend) | Extend adds a Template to a Startup’s bases, pinned to a Version, so the Startup inherits its definition. | [Agent](/business/nouns/agent) | [`Template.extended`](/business/events/Template.extended) | None. |
| [Template.promote](/business/nouns/template/promote) | Promote moves one Startup’s refinement into a Template, so every Startup that extends the Template inherits it. | [Agent](/business/nouns/agent) | [`Template.promoted`](/business/events/Template.promoted) | None. |
| [Template.upgrade](/business/nouns/template/upgrade) | Upgrade moves a Startup to a newer Version of a Template it extends, through a Change it can review. | [Agent](/business/nouns/agent) | [`Template.upgraded`](/business/events/Template.upgraded) | None. |
| <a id="create"></a>[Template.create](/business/nouns/template/create) | Creates a Template. Inherited from [Noun](/business/nouns/noun). | None. | `Template.created` | Two-way: `try`, `send`, `do` |
| <a id="get"></a>[Template.get](/business/nouns/template/get) | Returns one Template by id. Inherited from [Noun](/business/nouns/noun). | None. | None. | Read: `try`, `do` |
| <a id="list"></a>[Template.list](/business/nouns/template/list) | Returns Templates, newest first, one page at a time. Inherited from [Noun](/business/nouns/noun). | None. | None. | Read: `try`, `do` |
| <a id="update"></a>[Template.update](/business/nouns/template/update) | Changes the given properties of a Template. Inherited from [Noun](/business/nouns/noun). | None. | `Template.updated` | Two-way: `try`, `send`, `do` |
| <a id="delete"></a>[Template.delete](/business/nouns/template/delete) | Deletes a Template; its history is kept. Inherited from [Noun](/business/nouns/noun). | None. | `Template.deleted` | One-way: `send`, `do` |

## Permissions
Which Access level may call each Verb. One-way Verbs wait their delay window.

| Operation | `owner` | `admin` | `member` | `viewer` |
| --- | --- | --- | --- | --- |
| `Template.create` | Yes | Yes | Yes | No |
| `Template.get` | Yes | Yes | Yes | Yes |
| `Template.list` | Yes | Yes | Yes | Yes |
| `Template.update` | Yes | Yes | Yes | No |
| `Template.delete` | Yes | Yes | Yes | No |
| `Template.extend` | Yes | Yes | Yes | No |
| `Template.promote` | Yes | Yes | Yes | No |
| `Template.upgrade` | Yes | Yes | Yes | No |

## Call it

**Ask**

```text
Extend the latest template with a startup.
```

**API**

```bash
curl -X POST https://api.sb/quietcopy.com/templates/template_1/extend \
  -H "Authorization: Bearer $STARTUP_BUILDER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"startup":"startup_1"}'
```

```json
{
  "api": "https://api.sb/quietcopy.com",
  "startup": {
    "$id": "https://api.sb/quietcopy.com/startups/startup_1",
    "$type": "Startup",
    "name": "QuietCopy"
  },
  "template": {
    "$id": "https://api.sb/quietcopy.com/templates/template_1",
    "$type": "Template",
    "body": "Example body"
  },
  "action": {
    "$id": "https://api.sb/quietcopy.com/actions/action_1",
    "operation": "Template.extend",
    "status": "done"
  },
  "links": {
    "self": "https://api.sb/quietcopy.com/actions/action_1"
  }
}
```

**SDK**

```ts
import { $ } from 'startup-builder'

const { startup, template } = await $.Template.extend({ template: 'template_1', startup: 'startup_1' })
```

**CLI**

```bash
npx startup-builder do Template.extend --json '{"template":"template_1","startup":"startup_1"}'
```

**MCP**

```json
{
  "name": "do",
  "arguments": {
    "code": "return await $.Template.extend({ template: 'template_1', startup: 'startup_1' })"
  }
}
```

## Example
A Startup that sells a collections [Agent](/business/nouns/agent) extends the [Agent as a Service](/products/templates/agent-as-a-service) Template, then overrides the default [Price](/business/nouns/price) to $150 a month.