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

# Generate social cards from a template

> Create 1200 × 630 share images from one Handlebars layout.

Use a single template for your blog's share images. Pass each post's title and category as `page.templateData`. The template keeps the canvas at 1200 × 630 pixels and wraps long titles within the same layout.

## Render one image per post

Install the [Doczilla Node SDK](https://docs.doczilla.app/libraries/nodejs.md) with `npm install @doczilla/node`. Set `DOCZILLA_API_KEY` and run `node render-social-cards.mjs` alongside the template.

```javascript render-social-cards.mjs theme={null}
import { readFile, writeFile } from 'node:fs/promises'
import Doczilla, { ScreenshotOptions } from '@doczilla/node'

const apiKey = process.env.DOCZILLA_API_KEY
if (!apiKey) {
  throw new Error('Set DOCZILLA_API_KEY')
}

const doczilla = new Doczilla(apiKey)

const htmlTemplate = await readFile(new URL('./social-card.html', import.meta.url), 'utf8')
const posts = [
  {
    slug: 'release-notes',
    category: 'Updates',
    title: 'Release notes for May'
  },
  {
    slug: 'writing-release-notes',
    category: 'Guide',
    title: 'How to write release notes that help readers understand what changed'
  }
]

for (const { slug, ...templateData } of posts) {
  const image = await doczilla.screenshot.direct({
    page: {
      htmlTemplate, templateData
    },
    screenshot: {
      type: ScreenshotOptions.type.PNG,
      viewport: {
        width: 1200,
        height: 630,
        deviceScaleFactor: 1
      }
    }
  })

  await writeFile(`${slug}.png`, image)
}
```

## HTML

Save the HTML below as `social-card.html`. Handlebars escapes text passed through double braces.

> [accordion] Social card HTML template
>
> <Snippet file="code-group/social-cards-html.md" />

## Output

![Fieldnotes social card titled Release notes for May](https://mintcdn.com/doczilla/Teqhl5ABLAafgT50/images/examples/social-release-notes.png?fit=max\&auto=format\&n=Teqhl5ABLAafgT50\&q=85\&s=39a1402ac73fe738a42d9333f5e646ac)

Short title

![Fieldnotes social card with a long title about writing release notes](https://mintcdn.com/doczilla/Teqhl5ABLAafgT50/images/examples/social-writing-release-notes.png?fit=max\&auto=format\&n=Teqhl5ABLAafgT50\&q=85\&s=b99f61fac6b143abef99644e80bf4213)

Long title wrapped within the same canvas

Publish the images at publicly accessible URLs for your pages' `og:image` tags. The sample clips titles that exceed three lines. Preview your longest titles before publishing. See the [Templating guide](https://docs.doczilla.app/templating/introduction.md) for more ways to reuse layouts.


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