# Render template design

`templates_render`

Turns a design, the blocks a template can be built from, into the HTML and the plain text an email gets from it. Nothing is saved and nothing is sent. Give values for variables to see the message filled in.

Needs the scope: `templates:read`

## Arguments

- `design` (object, required): The blocks to render, shaped like the `design` of a template.
- `design.preview` (string): The line a mail app shows beside the subject before the message is opened. `{{NAME}}` marks a variable. Up to 256 characters.
- `design.style` (Record<string, string | number>): CSS for the whole message, by property name. A background colour fills the page, a `maxWidth` centres the content, and `fontFamily`, `fontSize` and `lineHeight` are what text gets unless a block sets its own.
- `design.dark` (Record<string, string | number>): Colours for the whole message for a reader in dark mode, by property name: `backgroundColor` fills the page, and `color` and `borderColor` go to the content. It takes: color, backgroundColor, borderColor.
- `design.fonts` (object[]): Fonts the message loads from an address of your own, 4 at most. A block or the page uses one by naming its `family` in `fontFamily`, and gets its `fallback` added for the mail apps that load no web fonts.
- `design.fonts[].family` (string, required): The name of the font, such as `Inter`. A block or the page uses the font by naming it in `fontFamily`.
- `design.fonts[].fallback` (string, required): The fonts to use where this one does not load, the one you want most first, such as `Helvetica, Arial, sans-serif`. Pick fonts every device has.
- `design.fonts[].url` (string, required): The full `https` address of the font file, on your own domain or a CDN. It cannot be a variable. Up to 2,048 characters.
- `design.fonts[].format` (string, required): The format of the file: `woff2`, `woff`, `truetype` or `opentype`. One of: `woff2`, `woff`, `truetype`, `opentype`.
- `design.fonts[].weight` (number | string): The weight this file holds: a number from 100 to 900 in hundreds, or `normal` or `bold`. Without it, 400.
- `design.fonts[].style` (string): The style this file holds: `normal` or `italic`. Without it, `normal`. One of: `normal`, `italic`.
- `design.css` (string): CSS of your own for the whole message, up to 20000 characters. It goes into the head after the rules the design makes, and reaches a block by its `className`. A rule that has to beat the style a block carries needs `!important`. `</style`, `@import`, `expression(`, `javascript:`, `behavior:`, `-moz-binding` are refused.
- `design.body` (object[], required): The blocks of the message, from top to bottom. Up to 500 items.
- `design.body[].kind` (string, required): What the block is. `Section`, `Row`, `Column` and `Container` hold other blocks. `Text`, `Heading`, `Button`, `Link`, `Markdown`, `CodeBlock` and `CodeInline` hold text. `Img` is an image, `Hr` a line and `Html` custom code: HTML of your own that goes into the message as it is. One of: `Section`, `Row`, `Column`, `Container`, `Text`, `Heading`, `Button`, `Link`, `Img`, `Hr`, `Markdown`, `CodeBlock`, `CodeInline`, `Html`.
- `design.body[].id` (string): A name for the block that no other block of the design has: lowercase letters, digits and hyphens. Leave it out and the block gets one.
- `design.body[].style` (Record<string, string | number>): CSS for the block, by property name, such as `{ "fontSize": "16px", "color": "#111111" }`. Only properties that work in mail are taken.
- `design.body[].align` (string): Where the block sits across its line: `left`, `center` or `right`. One of: `left`, `center`, `right`.
- `design.body[].className` (string): Class names for the block, one or several with one space between them, such as `hero wide`, 200 characters at most. The `css` of the design reaches the block by them. A name cannot start with `r-`.
- `design.body[].only` (string): The one kind of screen the block shows on: `desktop` hides it on a phone, and `phone` shows it on a phone and nowhere else. Without it, the block shows everywhere. One of: `desktop`, `phone`.
- `design.body[].phone` (Record<string, string | number>): CSS that takes the place of the style of the block on a phone, a screen up to 600 pixels wide, by property name, such as `{ "fontSize": "14px", "padding": "12px" }`. It takes: fontSize, lineHeight, textAlign, padding, paddingTop, paddingRight, paddingBottom, paddingLeft, margin, marginTop, marginRight, marginBottom, marginLeft, width, maxWidth, height.
- `design.body[].dark` (Record<string, string | number>): Colours that take the place of the ones of the block for a reader in dark mode, by property name, such as `{ "color": "#f4f4f5" }`. It takes: color, backgroundColor, borderColor.
- `design.body[].text` (string): The words of a block that holds text, up to 20000 characters. `{{NAME}}` marks a variable. A `Markdown` block takes Markdown here, a `CodeBlock` takes the code and an `Html` block takes its HTML, up to 60000 characters.
- `design.body[].children` (unknown[]): The blocks inside a `Section`, a `Row`, a `Column` or a `Container`, each shaped like a block of `body`. A `Row` takes `Column` blocks only, and a `Column` sits in a `Row` only. Up to 500 items.
- `design.body[].href` (string): Where a `Button` or a `Link` leads: a full address, or one variable as the whole value, such as `{{URL}}`. Up to 2,048 characters.
- `design.body[].target` (string): Where the link opens: `_blank` for a new tab or `_self`. Without it, `_blank`. One of: `_blank`, `_self`.
- `design.body[].src` (string): The address of the picture of an `Img`: a full address, or one variable as the whole value. Up to 2,048 characters.
- `design.body[].alt` (string): What the picture of an `Img` shows, in words, for someone who cannot see it. Up to 512 characters.
- `design.body[].width` (string | number): The width of an `Img` or a `Column`: a number of pixels, or a length such as `50%`. Up to 32 characters.
- `design.body[].height` (string | number): The height of an `Img`: a number of pixels, or a length. Up to 32 characters.
- `design.body[].valign` (string): Where the content of a `Column` sits: `top`, `middle` or `bottom`. One of: `top`, `middle`, `bottom`.
- `design.body[].as` (string): The level of a `Heading`, from `h1` to `h6`. Without it, `h1`. One of: `h1`, `h2`, `h3`, `h4`, `h5`, `h6`.
- `design.body[].language` (string): The language of a `CodeBlock`, such as `typescript` or `bash`. One it does not know is shown as plain text. Up to 64 characters.
- `design.body[].theme` (string): The colours of a `CodeBlock`: `oneDark`, `oneLight`, `dracula`, `nord`, `vscDarkPlus`, `vs`, `ghcolors` or `materialLight`. Without it, `oneDark`. Up to 64 characters.
- `design.body[].lineNumbers` (boolean): Whether a `CodeBlock` numbers its lines.
- `design.body[].stack` (boolean): `true` puts the columns of a `Row` under each other on a phone. Only a `Row` takes it.
- `variables` (Record<string, string>): A value for a variable, by name. A variable with no value stays in the result as `{{NAME}}`.
- `marks` (boolean): `true` to mark every block in the HTML with `data-block` and its id, every variable in text with `data-variable` and its name, and the wrapper of custom code with `data-raw`, so an editor can find them. Leave it out for the HTML a template stores and sends.

## Returns

The answer comes back under `structuredContent`, with the same JSON as text in `content`. A call the API refuses comes back with `isError` set, and the code and the message under `structuredContent.error`. [MCP](https://opensend.sh/docs/mcp) shows how to connect a client.

- `html` (string): The HTML the design makes, as a whole document.
- `text` (string): The same message as plain text.

## Example

MCP:

```json
{
  "name": "templates_render",
  "arguments": {
    "design": {
      "fonts": [
        {
          "family": "Inter",
          "fallback": "Helvetica, Arial, sans-serif",
          "url": "https://cdn.example.com/fonts/inter.woff2",
          "format": "woff2"
        }
      ],
      "body": [
        {
          "kind": "Heading",
          "text": "Welcome, {{NAME}}",
          "style": {
            "fontFamily": "Inter"
          }
        },
        {
          "kind": "Text",
          "text": "Your plan is {{PLAN}}."
        },
        {
          "kind": "Button",
          "text": "Open your account",
          "href": "{{URL}}"
        }
      ]
    },
    "variables": {
      "NAME": "Ada"
    }
  }
}
```

Answer, under structuredContent:

```json
{
  "html": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html dir=\"ltr\" lang=\"en\"><head><meta content=\"text/html; charset=UTF-8\" http-equiv=\"Content-Type\"/><meta name=\"x-apple-disable-message-reformatting\"/><style>@font-face{font-family:Inter;font-style:normal;font-weight:400;font-display:swap;mso-font-alt:Helvetica;src:url(\"https://cdn.example.com/fonts/inter.woff2\") format('woff2')}</style></head><body><h1 style=\"font-family:Inter, Helvetica, Arial, sans-serif\">Welcome, Ada</h1><p style=\"font-size:14px;line-height:24px;margin-top:16px;margin-bottom:16px\">Your plan is {{PLAN}}.</p><a href=\"{{URL}}\" style=\"line-height:100%;text-decoration:none;display:inline-block;max-width:100%;mso-padding-alt:0px;padding:0px 0px 0px 0px\" target=\"_blank\"><span><!--[if mso]><i style=\"mso-font-width:0%;mso-text-raise:0\" hidden></i><![endif]--></span><span style=\"max-width:100%;display:inline-block;line-height:120%;mso-padding-alt:0px;mso-text-raise:0\">Open your account</span><span><!--[if mso]><i style=\"mso-font-width:0%\" hidden>&#8203;</i><![endif]--></span></a></body></html>",
  "text": "Welcome, Ada\n\nYour plan is {{PLAN}}.\n\nOpen your account {{URL}}"
}
```
