Snippets are reusable content blocks that you can add to your templates to make building and personalizing messages in Iterable even easier. With snippets, you can:
- Manage frequently used elements like email headers and footers
- Store complex logic blocks
- Update multiple templates at the same time
In this article
Required permissions
To create, edit, or delete a snippet, you'll need the Create and Manage Snippets permission.
What's in a snippet?
To work with snippets, there are a few terms you'll need to know.
Name
Give each of your snippets a helpful and descriptive name, because you'll use these names to reference them in your templates. Snippet names can include letters, numbers, spaces, dashes, and underscores.
To help make it easier for your team to organize and collaborate on your snippets, it can be helpful to use a consistent naming convention.
Snippet names are internal to your organization (your users won't ever see them).
IMPORTANT
Once you save a snippet, you can't change its name.
Snippet content
This is the content that will be inserted in any template that references the snippet. For example, a snippet's content might include a banner, a list of product recommendations, or a message footer.
Snippets can include:
-
HTML (including images)
To use an image in a snippet, you'll need to reference one that's already hosted somewhere. Be sure to close your HTML tags, and remember that some mediums (like SMS) can't render HTML.
-
CSS
Snippets support inline CSS on HTML tags (using the HTML
style
attribute). However,<style>
tags are not supported.Standard precedence rules apply to CSS contained in a snippet:
- A more-specific selector takes precedence over a less-specific one.
- If two CSS rules have the same specificity, the one that appears later in the code takes precedence.
- A CSS rule with
!important
always takes precedence.
-
Handlebars
To reference a user profile field, event field, or variable, use a Handlebars expression. For example,
{{location}}
or{{#if signedUp}}
. To learn more, read Personalizing Templates with Handlebars -
Data feeds
A snippet can reference data feeds. However, you'll need to make sure that any templates that reference the snippet are properly configured to use data feeds.
Snippets cannot include:
-
<script>
tags -
<iframe>
tags - JavaScript
- References to themselves
Variables
Variables (previously called Positional Parameters) are dynamic fields included in a snippet's definition, so that individual templates can customize them as needed.
When a template references a snippet, it should provide values for all of that snippet's variables. Then, the snippet's content can use the passed-in values however it needs (displaying them, using them for conditional logic, using them to modify styles, etc.)
For example, a snippet might define variables that require templates to pass in a CTA, a color, or a value that it can use to help decide what content to display (using conditional logic in Handlebars).
To learn more, read Customizing Snippets with Variables.
Snippet expression
This is the Handlebars code that Iterable generates for you when you create a snippet, and it's what you'll use to include the snippet in a template.
Think of a snippet expression like a shortcut. Instead of including a given chunk of content directly in every template that needs it, you can put that content in a snippet and use the snippet expression to include it wherever it's needed.
To learn how to use a snippet expression to add a snippet to a template, read Adding a Snippet to a Template.
Creating a snippet
The Snippets page is a central repository for all of the reusable content blocks in your Iterable project.
To create a new snippet:
Navigate to Content > Snippets and click New snippet.
Give your snippet a name. You won't be able to change this later, so make sure you choose a unique, descriptive name (don't use
test123
).(Optional) Add variables, so that template can customize the snippet as needed.
(Optional) Add a description to help your teammates understand what this snippet is for.
-
Add your snippet's content, in the Editor section.
NOTE
You can create snippets using either the WYSIWYG or Side by Side editor. To switch between these two options, go to Settings > Project Settings.
Click Save snippet.
To learn more about creating snippets, see Tutorial: Create Your First Snippet.
Editing a snippet
IMPORTANT
Be careful! When you save a snippet, any changes you've made will immediately start to affect every template that references that snippet.
To modify a snippet, it's best to save it as a copy, test it, and then update the original after you've confirmed that your changes are working as expected.
To save a snippet as a copy:
Navigate to Content > Snippets.
Open the original snippet and make any necessary changes.
Click Save snippet.
-
In the Save Snippet menu that opens, click Save as new.
Give your new snippet a name. Then, click Save snippet.
Test the new snippet by adding it to a template, previewing it with data, and sending proofs.
If everything looks good, copy the updated content over to the original snippet. This is a global change, and it will update all templates and campaigns that reference that snippet.
Snippet editors
To edit a snippet, you can use either the WYSIWYG or Side by Side Editor. You can switch between these editors as needed.
A few things to note about snippet editors:
If you've disabled the WYSIWYG editor in your project settings, snippets will always open in the Side by Side editor.
Snippets that contain HTML tags will always open in the WYSIWYG editor, unless it has been disabled in your project settings. From there, you can switch to the Side by Side editor if needed.
Snippets that do not contain HTML tags will always open in the Side by Side editor. From there, you can switch to the WYSIWYG editor, but it will surround your content with HTML tags that you may not want.
NOTE
Because the WYSIWYG editor can add unexpected HTML tags to your content:
Use the Side by Side editor to edit plain text snippets (snippets without any HTML tags).
To verify a snippet's HTML after viewing or editing it in the WYSIWYG editor, use the Side by Side editor or the WYSIWYG editor source view.
For examples of code changes and suggested courses of action, check out The WYSIWYG Editor.
Copying a snippet
To make a copy of a snippet:
Navigate to Content > Snippets and find or open the snippet you want to copy.
Click the three dots menu for the snippet you want to copy, and click Make a copy.
Choose whether you want to copy the snippet to the same project or a different one.
If you're copying the snippet to a different project, select the name of the project you want to copy the snippet to.
(Optional) Edit the snippet name.
Click Copy snippet.
Want to learn more?
For more information about some of the topics in this article, check out this Iterable Academy course. Iterable Academy is open to everyone — you don't need to be an Iterable customer!