# Document templates

> Templates for invoices, credit notes, quotes, orders, dunning letters, delivery notes and statements per legal entity and language, reusable text blocks, one versioned variable contract per document type, and render_document, which returns the variables, the chosen template and its texts. An issued invoice or credit note is frozen with the template version it used, so rendering it again never changes it.

- Category: Tenancy & accounts
- Module: `document-templates`
- Modes: `managed`, `custom`
- Docs: https://bettersupabase.com/docs/blocks/document-templates
- Page: https://bettersupabase.com/blocks/document-templates

## Install

```bash
npx better-supabase add document-templates
```

The command also installs `updated-at`, `memberships`, `permissions`, `settings`, `legal-entities`.

## Configure

Add the block to `better-supabase.config.ts`:

```ts
import { defineConfig } from "better-supabase/config";

export default defineConfig({
  blocks: {
    // Required by document-templates; add installs them too.
    "updated-at": {},
    memberships: {},
    permissions: {},
    settings: {},
    "legal-entities": {},
    // Modes: "managed", "custom". The default is "managed".
    "document-templates": { mode: "managed" },
  },
});
```

## Client

The block has no React entry yet. Its server-side TypeScript is in `better-supabase/blocks/document-templates`.

## Events

- `document_snapshot.created`
- `document_template.created`
- `document_template.updated`
- `document_text_block.created`
- `document_text_block.updated`

## Related blocks

Requires: [memberships](https://bettersupabase.com/blocks/memberships.md), [permissions](https://bettersupabase.com/blocks/permissions.md), [legal-entities](https://bettersupabase.com/blocks/legal-entities.md)

Works with: [invoices](https://bettersupabase.com/blocks/invoices.md), [quotes](https://bettersupabase.com/blocks/quotes.md), [orders](https://bettersupabase.com/blocks/orders.md), [shipments](https://bettersupabase.com/blocks/shipments.md), [contacts](https://bettersupabase.com/blocks/contacts.md), [tax](https://bettersupabase.com/blocks/tax.md), [imports](https://bettersupabase.com/blocks/imports.md), [outbox](https://bettersupabase.com/blocks/outbox.md), [audit](https://bettersupabase.com/blocks/audit.md)
