Using Postmark Layouts

Previously, if your Templates shared common CSS elements, or headers and footers, the code for each Template needed to be managed independently. With Layouts, your receipts, welcome emails, and password reset can share common elements. Each individual Template only contains the content of the email, while the reusable content is shared with the chosen Layout.

Using Layouts

To give you a head start, Postmark comes with a few starter Layouts. The adventurous can also code their own Layout from scratch.

Adding a Layout

Navigate to one of your Postmark Servers, and select Templates.

Choose Layouts then Add layout.

Postmark will show our built-in starter layouts. For this example, we’ll choose Basic.

After selecting the layout, it’s added. You’re now ready to create a beautiful Layout for your Templates.

Editing Layouts

After adding your layout, it’s a snap to edit it using Postmark’s editor. In the editor, you can add or edit the HTML and CSS, then see a live preview.

Like Postmark’s starter Templates, the starter Layouts include CSS in a style block in the head of the email, instead of inline with the content like most email clients prefer. Postmark will automatically inline those styles when the email is delivered. This makes it easier for you to edit while still bringing all the benefits and reliability of inlining.

To indicate where your template content will go, use the content placeholder:

{{{ @content }}}

A single content placeholder is required to save a layout.

By default, the content placeholder is added to the starter Layouts.

Worried about forgetting the syntax? The Layout editor has a handy button to add the placeholder at your cursor’s location.

Associating Templates with a Layout

New or existing Templates can use Layouts.

Add a Layout to a new Template:

When adding the new Template, there’s an option to use the Template with an existing Layout. Or you can add a Layout when creating the Template.

Use a Layout with an existing Template:

When viewing an existing Template within Postmark’s editor, there is an option to associate the Template with a Layout.

Add a new layout will automatically add a basic layout to the template and associates it to your Template.

After selecting a Layout, choosing
Preview will show the Template content as it will appear with the Layout. This lets you see how your Template will look when sending an email. If you have multiple Layouts, you can also switch between Layouts to see how the Template content would appear in different Layouts.

Want to edit a Layout quickly? While viewing the different Layouts you can select a Layout to open in a new window, and edit it. Refreshing the Template page will let you see any Layout changes when previewing.

Templates inherit a Layout’s variables

When sending email using a Template, the variables from the Layout are available when using the
template model API parameter.

For example, if
product_name is a variable from the Layout, when sending a message with the API, the Template can pass
product_name in its Template model.

Using an alias with layouts

Each alias for Layouts and Templates are unique to a Server in Postmark. It’s not possible for a Template to have the alias of
welcome and a Layout to have an alias of
welcome in the same Server.

Pushing layouts to another server

Are you a fan of Postmark’s ability to push Templates from a Server to another? Good news! Along with Templates, pushing Layouts to another Server is possible. Pushing sends every Template and Layout from one Server to another Server.

For example — Let’s say you’ve added a Layout and associated Templates to your staging server. With pushing, after testing the Templates, you’re able to push the Templates and Layouts to your production server.

To push Layouts and Templates

Navigate to one of your Postmark Servers, and select Templates.

Choose Push to another server.

The changes about to be pushed will display. Along with the ability to preview the changes.

Once you’re ready to push, select Push now.

How to view which Templates are using a Layout

Navigate to one of your Postmark Servers, and select Templates.

Choose Layouts.

When viewing the Layouts, its listed which Templates are using it.

Pro Tip: Hovering over n templates will show the Templates using the Layout.