# Building Blocks with DML


Dyspatch blocks are modular, responsive, customizable, and straightforward to build with <a href="https://docs.dyspatch.io/dml/" target="_blank">Dyspatch Markup Language (DML)</a>. Once a block is created you can use it in the email builder to create emails quickly.

## Using DML to Build Blocks
We built DML to make coding responsive email blocks fast and effortless. Design your block with structural DML tags like `<dys-column>` and add common email elements with DML tags like text `<dys-text>`, images `<dys-img>`, and buttons `<dys-button>`. You can also use DML to create dynamic blocks and add personalizations, like variables `@{variable_name}`.

The blocks you build with DML will be available in the email builder and used to create new email. Emails created from blocks can then be exported from Dyspatch to any of our <a href="/integrations/" target="_blank">ESP direct integrations</a> or to any of our <a href="https://docs.dyspatch.io/dml/#export-languages" target="_blank">supported export languages</a>.

## Create a New Block
There are two ways to create a new block. Creating a block [from the Blocks & Apps tab](#new-block-from-blocks--apps-tab) will require toggling on all themes you'd like to make the block available in. Creating a block [from the Themes tab](#new-block-from-themes-tab) will assign the Block to that theme automatically.

### New Block from Blocks & Apps Tab
Select the **Blocks & Apps** tab from the left menu, click **Create** then **New Block**.

![Make a new block in the Block tab in Dyspatch](https://docs.dyspatch.io/img/emails/new-block.png)

This block will need to be [manually added](/blocks_and_themes/styling_with_themes/#adding-blocks-to-themes) to your theme or themes before it can be used in an email.

### New Block from Themes Tab
From the <a href="https://app.dyspatch.io/themes" target="_blank">Themes tab</a>, select the theme you'd like to use your new block in then click **Create > New Block**.

![Create a new block from the Themes tab in Dyspatch](https://docs.dyspatch.io/img/emails/new-block-from-themes.png)

### Duplicate a Block
To make a new version of an existing block, duplicate the block from either the **Blocks & Apps** tab, or the **Themes** tab. Select **Duplicate** from the " <svg xmlns="http://www.w3.org/2000/svg" width="3" height="11" viewBox="0 0 3 11"><title>3 dot</title><path fill="currentColor" fill-rule="evenodd" d="M1.344 8c.363 0 .677.133.944.4.267.267.4.581.4.944s-.133.677-.4.944c-.267.267-.581.4-.944.4s-.677-.133-.944-.4a1.291 1.291 0 0 1-.4-.944c0-.363.133-.677.4-.944.267-.267.581-.4.944-.4zm0-4c.363 0 .677.133.944.4.267.267.4.581.4.944s-.133.677-.4.944c-.267.267-.581.4-.944.4s-.677-.133-.944-.4a1.291 1.291 0 0 1-.4-.944c0-.363.133-.677.4-.944.267-.267.581-.4.944-.4zm0-1.312a1.29 1.29 0 0 1-.944-.4 1.291 1.291 0 0 1-.4-.944C0 .981.133.667.4.4.667.133.981 0 1.344 0s.677.133.944.4c.267.267.4.581.4.944s-.133.677-.4.944a1.29 1.29 0 0 1-.944.4z"></path></svg> " menu icon for the block you'd like to duplicate. Either way, your block's theme assignment settings will follow to the new block.

![Duplicate a block in Dyspatch](https://docs.dyspatch.io/img/emails/duplicate-block-menu.png)

## Starting in the Block Editor
A new block will already have the basic DML structure in the Block Editor.

![The block editor starting DML ready to go](https://docs.dyspatch.io/img/emails/build-blocks-block-editor.png)

### Style with Attributes
Each DML tag has attributes for adding style to the element. Using the attributes available for a `<dys-text>` tag we can make the text larger, add color, and assign a font to customize the style of this element.

![The block editor with attributes added to the dys-text for styling](https://docs.dyspatch.io/img/emails/build-blocks-attributes.png)

See the <a href="https://docs.dyspatch.io/dml/#dys-text" target="_blank">DML docs</a> for all available attributes for each tag.

<div class="highlight tip">If your theme has <a href="/blocks_and_themes/styling_with_themes/#dys-attributes"><code class="language-text">&lt;dys-attributes&gt;</code></a> set for your DML element, those will be applied to the element in the email. Any style attributes set on the element in the block will override theme-level attributes</div>

### Make Content Editable
Add an `editable` attribute with a unique name to allow email creators to customize the content in the email builder.

![The block editor with an editable attribute added to the dys-text](https://docs.dyspatch.io/img/emails/build-blocks-editable.png)

<div class="highlight note">Each editable attribute requires a name that is <em>unique</em> to the block</div>

The editable attribute is available for many DML and HTML elements, allowing you to control which content in the block will be available for customization in the email builder. For example, an editable attribute added to a `<dys-img>` tag will allow the src, alt text, title, and href to be editable in the email builder.

When an editable attribute is added to an element, the content becomes placeholder text that will be visible and editable in the email builder. Without the editable attribute, the content saved in the block will be locked and unavailable for editing in the email builder. Find out more about [editable content here](/blocks_and_themes/using_editable/).

<div class="highlight tip">For dialing in editable control, see how to <a href="/blocks_and_themes/styling_with_themes/#enable-editable-styles-for-blocks">enable editable styles for blocks</a> for a theme</div>

## DML Templating
Add personalization and templating logic to your block with DML. DML supports variables `@{variable_name}` and expressions, like if statements `<dys-if cond="conditional_name"></dys-if>`. Find out more about <a href="https://docs.dyspatch.io/dml/#templating" target="_blank">DML templating here</a>.

![A variable and an if statement in the block editor](https://docs.dyspatch.io/img/emails/build-blocks-templating.png)

The logic you add using DML can be exported to any of our <a href="/integrations/" target="_blank">ESP direct integrations</a> or as any of our <a href="https://docs.dyspatch.io/dml/#export-languages" target="_blank">supported export languages</a>, so you can use your Dyspatch emails in multiple email sending platforms.

### Sample Data
Add test data on the **Data** tab to preview your block's variables and check your templating logic with the same kind of data you would use to send your emails.

You can input and edit your sample data with the visual editor or the Code editor by toggling the icons next to *Custom Variables*.

![Data in the sample data tab in the block editor {'firstname':'Rowan','membership': true}](https://docs.dyspatch.io/img/emails/preview-data-both-views.png)

See more on [Testing Your Email with Sample Data](/emails/testing_your_email_with_preview_data/).

<div class="highlight tip">Use <a href="/emails/using_customer_profiles" target="_blank">Customer Profiles</a> to store multiple scenarios and customer types throughout your organization</div>

### Localizations
Manage your [block-level localizations](/localization/block_localization/) on the **Localizations** tab. This is typically used for non-editable content that will be the same across all emails where the block is used.

![Localizing your block](https://docs.dyspatch.io/img/emails/build-blocks-localization.png)

Check out our Knowledge Base to learn more about [localization in Dyspatch](/localization) and dig deeper into [Translating Blocks with Block Localization](/localization/block_localization/).

<div class="highlight note">To prevent translated content from changing, DML elements can be <i>localizable</i> in the block, or <i>editable</i> in the email builder, but not both</div>

## Add Block to Themes

From the **Settings > Theme Assignment** tab in the block editor you can preview how your block will look in different themes as well as add your block to a theme by using the toggle on the right.

![The theme tab in the block editor shows which themes the block is in](https://docs.dyspatch.io/img/emails/build-blocks-theme.png)

<div class="highlight note">A theme must be active on a block to use it in an email using that theme</div>

## Accessing Block Revision History

View, rename, and restore previous saved versions of your blocks from the block version history list. Access the list from the history icon next to the block name in the block builder

![Arrow pointing to history icon in the block builder](https://docs.dyspatch.io/img/emails/block-revision.png)

### Preview Previous Block Versions

Click the saved version name from the list to view a read-only preview of the block's code and appearance.

![Block revision history list of previous versions with code and image preview on the right](https://docs.dyspatch.io/img/emails/block-revision-list.png)

<div class="highlight note">Users with <b>Editor permissions</b> can only view revision history. <b>Developers</b> & <b>Admins</b> can view, rename, and restore revisions</div>

### Rename Previous Block Versions

To rename your revisions, select **Name this version** from the three-dot menu to the right of the version name.

![Block revision history list of previous versions with code and image preview on the right](https://docs.dyspatch.io/img/emails/block-revision-naming.png)

### Restore Previous Block Versions

To restore a previous version of the block, select it from the list then click the **Restore this Version** button.

![Block revision history list with restored version title and restore this version button enabled](https://docs.dyspatch.io/img/emails/block-revision-restored.png)

Restoring a block verion will create a new version that is appended to the version history list.

<div class="highlight tip">Restoring a block revision recovers all translated text</div>

## Add a Figma Link to your Block

If your team uses Figma as the single source of truth to keep designs consistent across all channels, like ours does, link to the Figma design file under **Settings > Block Details**.

![Block builder with a figma file attached and figma interactive screen](https://docs.dyspatch.io/img/emails/block-builder-figma.png)

This will allow block builders to preview and interact with the design file directly in the block builder, matching pixels 1:1 and ensuring email design accuracy.

## Importing Blocks

You can import one block into another to create a single source of truth for shared elements across your design system. When you update the source block, every block that imports it reflects the change on the next save.

Use the **Import Block** button in the block editor to get started. For full details and DML syntax, see [Importing Blocks](/blocks_and_themes/importing_blocks/).

## Designing Your Email System

For best practices on structuring blocks and themes for reuse — including naming conventions, blueprints, and how to use the Dyspatch Figma community file — see [Designing Your Emails for Dyspatch](/blocks_and_themes/designing_for_dyspatch/).

## Check out our DML documentation
<a href="https://docs.dyspatch.io/dml/" target="_blank" rel="noopener noreferrer">Head over to our DML docs</a> to read more about DML and do some interactive learning in our DML Playground.

<div class="highlight tip">If you prefer fully guided interactive training then <a href="https://university.dyspatch.io/" target="_blank" rel="noopener noreferrer">Dyspatch University</a> is your next&nbsp;stop&nbsp;🎓</div>
