@maily-to/render
TypeScript icon, indicating that this package has built-in type declarations

0.0.13 • Public • Published

@maily-to/render
Transform Maily content into HTML email templates.

Get Maily Editor


Install

Install @maily-to/render from your command line.

pnpm add @maily-to/render

Getting started

Convert React components into a HTML string.

import { render } from '@maily-to/render';

const html = await render({
  type: 'doc',
  content: [
    {
      type: 'paragraph',
      content: [
        {
          type: 'text',
          text: 'Hello World!',
        },
      ],
    },
  ],
});

Variables

You can replace variables in the content.

import { Maily } from '@maily-to/render';

const maily = new Maily({
  type: 'doc',
  content: [
    {
      type: 'paragraph',
      attrs: { textAlign: 'left' },
      content: [
        {
          type: 'variable',
          attrs: {
            id: 'currentDate',
            fallback: 'now',
            showIfKey: null,
          },
        },
      ],
    },
  ],
});

maily.setVariableValue('currentDate', new Date().toISOString());
const html = await maily.render();

Payloads

Payload values are used for the For Loop and Show If blocks.

// (Omitted repeated imports)

const maily = new Maily({
  type: 'doc',
  content: [
    {
      type: 'for',
      attrs: { each: 'items', showIfKey: null },
      content: [
        {
          type: 'paragraph',
          attrs: { textAlign: 'left' },
          content: [{ type: 'text', text: 'Hello' }],
        },
      ],
    },
  ],
});

maily.setPayloadValue('items', ['Alice', 'Bob', 'Charlie']);
const html = await maily.render();

Contributions

Feel free to submit pull requests, create issues, or spread the word.

License

MIT © Arik Chakma

Readme

Keywords

Package Sidebar

Install

npm i @maily-to/render

Weekly Downloads

379

Version

0.0.13

License

MIT

Unpacked Size

60.8 kB

Total Files

7

Last publish

Collaborators

  • arikchakma