Templates

Templates let you save a movie script once and render it many times with different content. Use variable placeholders to swap text, images, colors, and other values at render time.

What are templates?

A template is a saved movie script that contains {{variable}} placeholders in any string field. When you render from a template, you provide a variables object and PhantomFlow replaces every placeholder with the corresponding value before rendering.

This is useful for generating personalized videos at scale — product demos, social media ads, onboarding videos, reports, and more — without rebuilding the movie script each time.

Creating a template

Use POST /api/templates with a name and a movie script. Place {{variable_name}} anywhere a string value is expected.

curl -X POST https://api.phantomflow.dev/api/templates \
  -H "x-api-key: ve_live_your_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Product Demo",
    "script": {
      "width": 1920,
      "height": 1080,
      "scenes": [
        {
          "duration": 5,
          "elements": [
            {
              "type": "text",
              "text": "{{headline}}",
              "font_size": 64,
              "color": "#FFFFFF",
              "position": "center"
            },
            {
              "type": "text",
              "text": "{{subtitle}}",
              "font_size": 32,
              "color": "#CCCCCC",
              "position": "bottom-center"
            }
          ]
        },
        {
          "duration": 5,
          "elements": [
            {
              "type": "image",
              "src": "{{product_image}}",
              "position": "center"
            }
          ]
        }
      ]
    },
    "is_public": false
  }'

Rendering from a template

Use POST /api/render/template with the template ID and a variables object. Every {{key}} in the script is replaced with the matching value from the variables object.

curl -X POST https://api.phantomflow.dev/api/render/template \
  -H "x-api-key: ve_live_your_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "template_id": "tpl_a1b2c3d4e5f6",
    "variables": {
      "headline": "Summer Sale",
      "subtitle": "50% Off Everything",
      "product_image": "https://example.com/product.jpg"
    }
  }'

Variable substitution syntax

Variables use double-brace syntax: {{variable_name}}. They can appear in any string field within the movie script, including:

  • Text element text field
  • Image/video src URLs
  • Color values (color, background)
  • Voice element text for narration
  • HTML element html and css fields

Variable values can be strings, numbers, or booleans. Numbers and booleans are converted to their string representation before substitution.

Managing templates

Templates support full CRUD operations. See the API Reference for detailed endpoint documentation.

OperationEndpointDescription
CreatePOST /api/templatesCreate a new template
ListGET /api/templatesList your templates
GetGET /api/templates/:idGet a template with its script
UpdatePUT /api/templates/:idUpdate name, script, or visibility
DeleteDELETE /api/templates/:idPermanently delete a template
RenderPOST /api/render/templateRender from a template with variables

Complete example

Here is a full template script for a product announcement video with three scenes. Each scene uses variables for dynamic content.

{
  "width": 1920,
  "height": 1080,
  "quality": "high",
  "scenes": [
    {
      "duration": 4,
      "background": "{{brand_color}}",
      "elements": [
        {
          "type": "text",
          "text": "{{company_name}}",
          "font_size": 48,
          "color": "#FFFFFF",
          "position": "top-center"
        },
        {
          "type": "text",
          "text": "{{headline}}",
          "font_size": 72,
          "color": "#FFFFFF",
          "position": "center",
          "bold": true
        }
      ]
    },
    {
      "duration": 5,
      "elements": [
        {
          "type": "image",
          "src": "{{product_image}}",
          "position": "center",
          "fade_in": 0.5
        },
        {
          "type": "text",
          "text": "{{product_name}}",
          "font_size": 36,
          "color": "#FFFFFF",
          "position": "bottom-center"
        }
      ]
    },
    {
      "duration": 4,
      "elements": [
        {
          "type": "text",
          "text": "{{cta_text}}",
          "font_size": 56,
          "color": "{{brand_color}}",
          "position": "center"
        },
        {
          "type": "text",
          "text": "{{website_url}}",
          "font_size": 28,
          "color": "#CCCCCC",
          "position": "bottom-center"
        }
      ]
    }
  ]
}