This FAQ provides answers to questions you may have about snippets.
# In this article
- How do I add a snippet to a template?
- What kinds of content can a snippet contain?
- Can I copy a snippet from one project to a different project?
- What if my snippet name matches another field name?
- Can I export the HTML from a snippet?
- Can I see performance data for my snippets, like how many users saw a particular snippet?
- I'm having trouble with HTML tags in my snippets. What should I do?
- Can I nest snippets inside each other?
- Can I use Catalog and Collections in my snippets?
- Can I use Handlebars conditional logic to control whether a snippet renders?
- Can I use Handlebars to reference user profile and event data in snippets?
- Can I reference data feeds in snippets?
- What happens when I delete a snippet?
- Can I recover a deleted snippet?
- What are the most common snippet mistakes?
- How do I style a snippet?
- Want to learn more?
# How do I add a snippet to a template?
See Adding a Snippet to a Template.
# What kinds of content can a snippet contain?
Text, HTML (including image tags that reference hosted images), CSS style
attributes (but not <style> tags), merge tags and other Handlebars expressions,
and references to data feeds and catalogs.
# Can I copy a snippet from one project to a different project?
Yes, you can! When you make a copy of the snippet, select Copy to: Another project and select the project you want to copy the snippet to.
Keep in mind:
Your snippet name has to be unique in each project. If there's already a snippet with the same name in the project you're trying to copy to, you'll need to change your snippet's name before you can copy it to the new project.
If your snippet contains nested snippets, the nested snippets won't automatically be copied when you duplicate the parent snippet. You'll need to copy those separately.
# What if my snippet name matches another field name?
Using the same text for a snippet name and a field name does not create a direct collision in a snippet expression.
- In
{{{ snippet "My_Snippet" }}}(or{{ snippet "My_Snippet" }}), the quoted value is interpreted as the snippet name for thesnippethelper. - Field references are resolved separately based on their own expressions.
The choice of {{ ... }} versus {{{ ... }}} changes escaping behavior only.
It does not change name resolution or collision behavior.
If your template also uses data feeds and user profile fields with overlapping field names, resolve those with the merge contexts setting and alias settings. For details, see Troubleshooting Data Feeds in Templates.
# Can I export the HTML from a snippet?
You can copy and paste the HTML from a snippet. To access its HTML in the WYSIWYG editor, toggle to Source mode.
# Can I see performance data for my snippets, like how many users saw a particular snippet?
Not at this time.
# I'm having trouble with HTML tags in my snippets. What should I do?
A few things to consider:
Some message fields (like Subject Line, Preheader Text, and SMS) aren't compatible with HTML.
If you're seeing unwanted HTML, open the snippet from the Snippets page, switch to Source mode in the WYSIWYG editor, and find and remove any unwanted HTML tags.
-
Additionally, make sure that the snippet expression you've placed in your template uses the appropriate number of curly braces:
If you want the snippet to render any HTML tags found in its content as actual HTML (so they affect styles, etc.), your snippet expression should use triple curly braces (for example,
{{{ snippet "My_Snippet" }}}).If you want HTML tags to render as text (so that the tags themselves appear in your message content), your snippet expression should use double curly braces (for example,
{{ snippet "My_Snippet" }}).
# Can I nest snippets inside each other?
Yes, you can. However, be careful and test thoroughly. Nested snippets take longer to render, and in some cases they may cause timeouts or send skips.
Also, remember that a snippet cannot reference itself.
# Can I use Catalog and Collections in my snippets?
Yes, but be careful and test thoroughly. Large/complex collections can increase the time it takes to render a snippet, and in some cases they may cause timeouts or send skips.
# Can I use Handlebars conditional logic to control whether a snippet renders?
Yes. You can wrap a snippet expression in any Handlebars conditional helper to control whether the snippet renders at all. For example, to render a snippet only for users who have opted in to promotions:
Or to render a different snippet depending on locale:
This is different from adding conditional logic inside a snippet's content. For an explanation of both approaches, see Using Conditional Logic with Snippets.
# Can I use Handlebars to reference user profile and event data in snippets?
Yes, you can. However, when you add dynamic logic to a snippet, it's a good idea to test thoroughly and preview your template with data to make sure that everything works as expected.
Also, when referencing user profile fields, remember that some users may not have the referenced field. To prevent the snippet from rendering blank space in these cases, it's a good idea to provide a fallback option (so that at least something displays, even if it's not highly personalized content).
Keep in mind that particularly complex logic, like referencing lots of user profile or custom event data, can increase template rendering times. In some cases, this may result in timeouts or send skips.
# Can I reference data feeds in snippets?
Yes, you can! This is a great way to build reusable content blocks that have dynamic content that changes based on the data feed. This is an advanced use case that puts together multiple pieces of functionality: a data feed, a snippet, and a template.
To learn how to pass data feed fields to a snippet and then use that snippet in your template, read Using Data Feeds in Snippets.
# What happens when I delete a snippet?
Before deleting a snippet, remove it from all of the templates and campaigns that reference it. Any recurring, triggered, or journey campaigns that reference a deleted snippet will show an error and stop sending until you update their templates.
However, it can sometimes take several hours for Iterable to fully delete a snippet. In the meantime, campaigns that reference it will continue to send, but without the snippet content.
# Can I recover a deleted snippet?
No. Once you delete a snippet, it cannot be recovered. Before deleting a snippet, make sure you don't need it anymore, or create a backup copy.
# What are the most common snippet mistakes?
Here are common mistakes when working with snippets and how to fix them:
-
Using double curly braces for an HTML snippet. If you see raw HTML tags
in your message (for example,
<strong>Hello</strong>appearing as text), the snippet expression is using{{ ... }}. Change it to{{{ ... }}}to render the HTML. For details, see Handling HTML in snippet content.
Passing variables in the wrong order. Variables are positional by default, so the order of values in the snippet expression must match the order the variables are defined in the snippet. Use named parameters to avoid relying on order.
Using an unquoted word instead of a quoted string in a named parameter. When using
key=valuenamed-parameter syntax, string values must be double-quoted. Writinglogin_type=sign_uptreatssign_upas a variable reference rather than the literal text, so the variable may render blank or unexpectedly. Uselogin_type="sign_up"for string literals. Booleans and numbers (for example,required=true,count=3) do not need quotes. For details, see Named parameters.Forgetting to pass all variables. If a snippet defines three variables but the expression only passes two values, the missing variable renders as blank.
Placing an HTML snippet in a non-HTML field. Fields like Subject Line, Preheader Text, and SMS message bodies don't render HTML. Place HTML snippets only in fields that actually support HTML, like email message bodies.
Saving a snippet that is actively used in campaigns. Any change saved to a snippet immediately affects every template and campaign that references it. To safely make changes, create a copy of the snippet first, test the copy, and then update the original. To learn more, see Editing a snippet.
# How do I style a snippet?
Snippets accept inline CSS on HTML tags (using the HTML style attribute). However,
<style> tags are not supported.
Standard precedence rules apply to CSS 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
!importantalways takes precedence.
As you build a snippet, test it with different templates to make sure that its styles appear as you'd like.
Some things to consider:
Complete control over styles. In cases where a template needs complete control over the styles of the content rendered by a snippet, it's probably best not to use the snippet, and to instead add the snippet's content directly into the template. You could potentially modify the styles of the snippet itself, but that would affect all templates that rely on the snippet, which may not be preferable.
Snippet styles vs. template styles. Even if you add styles to a snippet expression that you've placed in a template editor, the styles contained in the snippet definition itself can still win out. Don't assume that applying a style to a snippet expression (in any editor) will necessarily get you the output that you expect.
-
Overriding snippet styles. Sometimes you can use HTML to override the styles contained in a snippet's definition:
- Drag and Drop editor: If you place a snippet expression in an HTML block (rather than a Text block), you can add additional HTML to the HTML block's Content Properties pane.
- WYSIWYG editor: You can add HTML to the Source pane of the WYSIWYG editor.
- Side by Side editor: You can edit the HTML directly in the Side by Side editor.
Actively used snippets. Remember that any change saved to a snippet's content immediately affects every template and campaign that references it. To safely make changes, create a copy of the snippet to test changes first. To learn more, see Editing a snippet.
In all cases, test thoroughly. Use Preview and send proofs of your templates with various user profiles that represent a range of use cases before sending or activating a campaign.
# 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!
Iterable Academy
Support docs