doctype, <head> and <body> tags of your HTML - the kind of code that changes rarely and can be reused.
Layouts may include a <yield /> tag, which can be used to render a Template. This allows us to create a parent-child relationship between Layouts and Templates.
In Maizzle we add this <yield /> tag in the <body> of the main.html Layout, to define where a Template’s HTML should be injected.
Getting started
Layouts are typically stored in thelayouts directory.
Need to store them elsewhere? Make sure to update the config.
<yield /> tag, which is used to define where the Template’s HTML will be rendered.
Here’s a very basic layout.html:
layouts/main.html
For Tailwind CSS to work, Layouts must include it either via a
<style> tag like above or through a <link> tag that references a CSS file.emails/example.html
<x-main> tag name is based on the Layout’s file name, with the .html extension removed, here are some examples:
| Layout file name | Layout tag name |
|---|---|
layouts/main.html | <x-main> |
layouts/alt.html | <x-alt> |
Tailwind CSS
In order for Tailwind CSS to work, you need to include it in a<style> or <link> tag.
style tag
Add the@tailwind directives in a <style> tag inside the <head> of your Layout:
layouts/main.html
link tag
Maizzle also supports<link rel="stylesheet"> tags - it will try to read the file from the href attribute and process it with PostCSS (including Tailwind CSS). Note that this currently only works with local files.
layouts/main.html
Make sure to include the
inline attribute on the <link> tag, this will replace it with a <style> tag that can be inlined and is generally better supported in email clients.tailwind.css file:
css/tailwind.css
Variables
Variables from your Environment config or from the Template’s own Front Matter are available in a Layout under thepage object.
You can use the curly braces expression syntax to output variables in a Layout:
Environment
The Environment name is available underpage.env. You can use it to output stuff based on the build command that you ran.
For example, you could use page.env to output some content only when running the maizzle build production command:
layouts/layout.html
You may also use the
<env:production> tag, see the docs.