Skip to content

templates command

Derek Rushforth edited this page Dec 16, 2020 · 13 revisions

Provides a push and pull workflow for your email templates. This lets you store your templates in version control and push to Postmark via a CI/CD pipeline.

⚠️ Before you get started, make sure that all of your templates have an alias. Check out our help doc for more info.

Authentication is done by server token.

pull <output directory> [options]

Download templates from a Postmark server to your local file system.

$ postmark templates pull ~/Desktop/pm-templates

# Options
--overwrite, -o  Overwrite templates if they already exist [boolean]

Here’s an example of the directory structure that is downloaded:

pm-templates
├── _layouts
│   └── plain
│       ├── content.html
│       ├── content.txt
│       └── meta.json
└── password-reset
│   ├── content.html
│   ├── content.txt
│   └── meta.json
└── welcome
    ├── content.html
    └── meta.json

Layouts are located under the _layout folder and standard templates will be located in the root directory. Each template or layout gets its own folder that contains the HTML and text content, along with metadata in a JSON file.

Metadata

meta.json is required for pushing your templates to Postmark. This lets you keep track of and update values such as aliases, subjects, names, etc for your templates. Here is the JSON structure for standard templates versus layouts:

Standard Templates

{
  "Name": "Receipt",
  "Alias": "receipt",
  "Subject": "Receipt for {{ product_name }}",
  "TemplateType": "Standard",
  "LayoutTemplate": "plain"
}

Layouts

{
  "Name": "Plain",
  "Alias": "plain",
  "TemplateType": "Layout"
}

⚠️ Note: If you update the template alias in meta.json, be sure to rename the template’s directory so it matches. This prevents conflicts down the line when pulling templates.

push <templates directory> [options]

Pushes changed templates from the local file system to a Postmark server.

$ postmark templates push ~/Desktop/pm-templates

# Options
--force, -f  Disable confirmation before pushing templates           [boolean]
--all, -a    Push all local templates up to Postmark regardless of 
             whether they changed                                    [boolean]

By default, you will be asked to confirm your changes before pushing your templates.

You can force push templates which disables the confirmation by including the -f flag.

$ postmark templates push ~/Desktop/pm-templates -f

preview <templates directory> [options]

Spin up a local development server at http://localhost:3005 so that you can preview your templates and layouts. Be sure to pull your templates before running the preview command. See the release notes for more details.

$ postmark templates preview ~/Desktop/pm-templates

# Options
--port, -p  The port to open up the preview server on     [number] [default: 3005]