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

# Templates

> Create, manage, and render reusable templates

# Templates

Templates are reusable designs with dynamic variables. Create once, render with different data.

<Note>
  For expression syntax and conditional rendering, see [Expressions](/concepts/expressions).
</Note>

## Endpoints

| Method | Endpoint | Description |
| - | - | - |
| `GET` | `/templates` | [List templates](/api-reference/endpoints/templates/list) |
| `POST` | `/templates` | [Create template](/api-reference/endpoints/templates/create) |
| `GET` | `/templates/{uid}` | [Get template](/api-reference/endpoints/templates/get) |
| `PUT` | `/templates/{uid}` | [Update template](/api-reference/endpoints/templates/update) |
| `DELETE` | `/templates/{uid}` | [Delete template](/api-reference/endpoints/templates/delete) |
| `POST` | `/templates/{uid}/render` | [Render template](/api-reference/endpoints/templates/render) to an image |
| `GET` | `/templates/{uid}/variables` | [Get variables](/api-reference/endpoints/templates/variables) defined in a template |

## Variable Types

Templates support different variable types in `{{variable}}` placeholders:

| Type | Example | Description |
| - | - | - |
| `string` | `"Hello World"` | Text content |
| `number` | `42`, `3.14` | Numeric values |
| `boolean` | `true`, `false` | Conditional rendering |
| `array` | `["a", "b"]` | Lists for iteration |
| `object` | `{name: "..."}` | Nested data |

## Using Variables in Templates

### Simple Interpolation

```html theme={null}
<h1>{{title}}</h1>
<p>By {{author}}</p>
```

### Conditional Rendering

```html theme={null}
<div _if="showBadge" class="badge">Premium</div>
```

### Expressions

```html theme={null}
<p>Total: {{currency(price * quantity, 'USD')}}</p>
```

See [Expressions](/concepts/expressions) for the full expression syntax.

## Layout Variants

Templates support multiple layout variants for different platforms. Each layout stores a separate canvas design optimized for a specific size (e.g., Twitter 1200x675, Instagram 1080x1080).

* Layouts are created via the **AI Resize** feature in the editor
* Variables are shared across all layouts
* Render a specific layout with the `layout` parameter, or multiple with `layouts`
* The `default` layout key refers to the base template

```bash theme={null}
# Render specific layout
curl -X POST /templates/{uid}/render \
  -d '{"variables": {"title": "Hello"}, "layout": "twitter-post"}'

# Render multiple layouts
curl -X POST /templates/{uid}/render \
  -d '{"variables": {"title": "Hello"}, "layouts": ["default", "twitter-post", "facebook-post"]}'
```

See [Rendering - Layout Variants](/concepts/rendering#layout-variants) for details.

## Template Content

A template requires either `html` or `fabricJSData` (FabricJS canvas JSON), but not both.

<Warning>
  Either `html` or `fabricJSData` is required when creating a template. You cannot provide both.
</Warning>


## OpenAPI

````yaml get /templates
openapi: 3.1.0
info:
  title: Pictify API
  version: 1.0.0
  description: |
    Generate images, GIFs, and PDFs from HTML templates programmatically.

    ## Authentication
    All API requests require a Bearer token in the Authorization header:
    ```
    Authorization: Bearer pk_live_your_api_key
    ```

    ## Rate Limits
    - Free: 60 requests/minute
    - Pro: 300 requests/minute
    - Business: 1,000 requests/minute

    Rate limit headers are included in all responses.
  contact:
    email: support@pictify.io
    url: https://pictify.io
  license:
    name: MIT
servers:
  - url: https://api.pictify.io
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Images
    description: Image generation endpoints
  - name: GIFs
    description: GIF generation and capture
  - name: PDFs
    description: PDF generation
  - name: Templates
    description: Template management
  - name: Batch
    description: Batch rendering operations
  - name: Webhooks
    description: Webhook subscription management
  - name: Bindings
    description: Data binding for auto-rendering
paths:
  /templates:
    get:
      tags:
        - Templates
      summary: List templates
      operationId: listTemplates
      parameters:
        - name: page
          in: query
          schema:
            type: integer
            default: 1
        - name: limit
          in: query
          schema:
            type: integer
            maximum: 100
            default: 12
        - name: sort
          in: query
          schema:
            type: string
            enum:
              - newest
              - oldest
              - name
            default: newest
        - name: outputFormat
          in: query
          schema:
            type: string
            enum:
              - all
              - image
              - pdf
            default: all
      responses:
        '200':
          description: List of templates
          content:
            application/json:
              schema:
                type: object
                properties:
                  templates:
                    type: array
                    items:
                      $ref: '#/components/schemas/Template'
                  pagination:
                    $ref: '#/components/schemas/Pagination'
components:
  schemas:
    Template:
      type: object
      properties:
        uid:
          type: string
        name:
          type: string
        engine:
          type: string
          enum:
            - fabric
            - html
          description: >
            Which renderer owns this template.

            - `fabric` — legacy canvas templates (fabricJSData)

            - `html` — Handlebars + HTML templates (html field, supports
            `{{var}}`, `{{#each}}`, `{{#if}}`, and the built-in helper library)
        html:
          type: string
          description: Handlebars source for `engine=html` templates.
        fabricJSData:
          type: object
          description: FabricJS canvas JSON for `engine=fabric` templates.
          additionalProperties: true
        jsEnabled:
          type: boolean
          description: >
            Only meaningful for `engine=html`. When true, scripts inside the
            template

            execute during render (Chart.js, KaTeX, animated SVG). Off by
            default

            to prevent runaway loops; a 30s hard timeout still applies.
          default: false
        strictVariables:
          type: boolean
          description: >
            Only meaningful for `engine=html`. When true, rendering fails with
            HTTP 422

            if a root-level variable referenced in the template was not
            supplied.

            Leave off if you rely on `{{#if optional}}` guards.
          default: false
        type:
          type: string
        category:
          type: string
        tags:
          type: array
          items:
            type: string
        width:
          type: integer
        height:
          type: integer
        thumbnail:
          type: string
          format: uri
        outputFormat:
          type: string
          enum:
            - image
            - pdf
          default: image
        pdfPreset:
          type: string
          description: Page preset used when `outputFormat=pdf`.
          enum:
            - A4
            - A4_LANDSCAPE
            - LETTER
            - LETTER_LANDSCAPE
            - LEGAL
            - A3
            - TABLOID
          default: A4
        variableDefinitions:
          type: array
          items:
            $ref: '#/components/schemas/VariableDefinition'
        pages:
          type: array
          description: Multi-page canvas pages (fabric engine).
          items:
            type: object
            properties:
              pageNumber:
                type: integer
              name:
                type: string
              fabricJSData:
                type: object
                additionalProperties: true
        layouts:
          type: object
          description: |
            Named layout variants. Keys are short identifiers matching
            `^[a-z0-9-]{1,64}$` (e.g. `twitter-post`, `og-image`). Each value
            overrides `width`, `height`, and renderer-specific data for that
            variant. Limit: 20 layouts per template.
          additionalProperties:
            type: object
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
    Pagination:
      type: object
      properties:
        page:
          type: integer
        limit:
          type: integer
        total:
          type: integer
        totalPages:
          type: integer
        hasNext:
          type: boolean
        hasPrev:
          type: boolean
    VariableDefinition:
      type: object
      required:
        - name
      properties:
        name:
          type: string
          description: Variable identifier. Must match the name used in `{{name}}` tokens.
        type:
          type: string
          enum:
            - text
            - image
            - color
            - chart
            - table
            - array
            - object
          default: text
        defaultValue:
          description: >
            Fallback value when the variable is not supplied at render time.

            Typed according to `type` — string for text/image/color/url, number
            for number,

            boolean for boolean, ISO date string for date, JSON array/object for
            array/object.
        description:
          type: string
        allowRawHtml:
          type: boolean
          description: >
            Only meaningful for `type=text` on `engine=html` templates. When
            true the value

            is NOT HTML-escaped at render time. Use with care — treat as trusted
            input.
          default: false
        validation:
          type: object
          properties:
            required:
              type: boolean
            minLength:
              type: integer
            maxLength:
              type: integer
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: API key obtained from the Pictify dashboard

````

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