Skip to main content
Helper function to define a template with type safety. Use this when creating custom templates for your Open Graph images.
For complete type definitions and interfaces, see the Type Definitions page.

Function Signature

function defineTemplate<T extends OgTemplateParams>(
  config: TemplateConfig<T>
): OgTemplate<T>;

Parameters

config
object
required
Template configuration

Returns

template
OgTemplate<T>
The defined template object that can be used with createRenderer

Example

import { defineTemplate } from "@ogify/core";

export type MyTemplateParams = {
  title: string;
  description: string;
};

const myTemplate = defineTemplate<MyTemplateParams>({
  fonts: [
    { name: "Inter", weight: 400 },
    { name: "Inter", weight: 700 },
  ],
  emojiProvider: "twemoji",
  renderer: ({ params, isRTL }) => {
    return `
      <div style="display: flex; width: 100%; height: 100%; direction: ${
        isRTL ? "rtl" : "ltr"
      };">
        <h1>${params.title}</h1>
        <p>${params.description}</p>
      </div>
    `;
  },
});

export default myTemplate;