Snippets

A snippet is a reusable piece of content that you can define in Airship for later use in your messages and templates.

A single snippet can be used in multiple channels. Snippets support text or HTML content and can be used for commonly used elements such as a copyright, header image, or custom CSS.

About snippets

When you edit a snippet, the changes automatically update anywhere that snippet is in use. For scheduled and recurring messages, resave the message to update the message with the latest version of the snippet. Example uses:

You create snippets in the dashboard, and you can insert them into your messages and templates using both the dashboard and API. You can assign keywords to your snippets so they are easily found in search.

 Tip

Add plain text and HTML in the same snippet for email messages so the plain text version appears for clients that do not support HTML, or for content that will be used across multiple channels.

 Note

Snippets are not supported for Scenes or In-App Automations.

Snippet format

A snippet has three parts:

  • Name — Used for identification in the list of all snippets in your project.
  • ID — Used to reference the snippet in your message. The snippet ID is generated automatically based on the snippet name, though you have the option to change it.
  • Content — The text or HTML that is inserted in your message where the snippet is referenced.

Personalizing snippets

You can use HandlebarsHandlebars is Airship’s templating language for personalization. Handlebars expressions use double curly braces wrapped around a content template, ranging from a simple variable, e.g., {{first_name}}, to complex evaluations of personalization data. and External Data FeedsA connection to an external API. When you send a message, Airship uses a response from that API to personalize messages. to insert Merge FieldsA variable in your message or template that you want to populate with a personalized value for each member of the audience. Merge fields use Handlebars syntax — {{merge_field}}. and Dynamic ContentVariable message content created using Handlebars syntax. The content is populated at send time, resulting in personalized messaging for each member of your audience. to personalize messages for each individual member of your audience. The dashboard supports previewing content that contains Handlebars; see: Previewing personalized content.

You can also pass template variables into a snippet to customize it for a specific message. For example, you might set up a “footer” snippet with a dynamic URL as its content like this:

<a href="https://example.com?utm_source={{utm_source}}&utm_campaign={{utm_campaign}}">

When including the snippet in your message, you can pass in one or more of the variables. You would add the snippet to your message text like this:

{{>footer utm_source="email" utm_campaign="newsletter"}}

Create a snippet

You can create a maximum of 1,000 snippets per project.

  1. Go to Content and select Snippets.
  2. Click Create snippet.
  3. Enter a name for the snippet. The snippet ID is automatically generated based on the name.
    • A snippet ID will not generate for a snippet name that contains only numbers and/or special characters.
    • If the name starts with a number and/or special characters, the generated ID omits the leading numbers and/or special characters.
    • Uppercase letters in the name are converted to lowercase in the ID.
    • Special characters in the name are converted to underscores in the ID and only appear if followed by numbers or letters.
  4. (Optional) Edit the snippet ID. Letters, numbers, and underscores only, and must start with a letter and end with a letter or number. You cannot change the snippet ID later.
  5. (Optional) Add keywords help organize your snippets. Enter a term in the search field and select from results, or click Add keyword: [term]. Click to remove a keyword. You can add up to 10 keywords.
  6. Click Continue.
  7. Add your plain text and/or HTML content.
    1. Click Add .
    2. Enter your content. The preview updates as you type.
       Important

      Do not insert a snippet into another snippet.

    3. Click Done.
  8. Click Save snippet when you are done adding content.

Insert a snippet

You can insert a snippet anywhere that supports HandlebarsHandlebars is Airship’s templating language for personalization. Handlebars expressions use double curly braces wrapped around a content template, ranging from a simple variable, e.g., {{first_name}}, to complex evaluations of personalization data. by entering its ID in the format {{>snippet_ID}}.

 Note

Make sure that the location where you are using a snippet supports the content defined in the snippet. For example, an image URL or HTML will not render in a push notification since push notifications only support plain text.

When using the Interactive EditorA tool for creating content for landing pages, Message Center, email, and In-App Automation. You can provide your own HTML or design using the drag-and-drop WYSIWYG option. and pasting or uploading HTML, a snippet is immediately rendered in the preview. If using the WYSIWYG option, you can insert snippets into text or HTML content, but they will not render in the editor; you must click Done to see the preview.

To include a snippet in an API request, reference the snippet by name in the snippet_references object, and invoke the snippet in your notification text. The example below loads a “signature” snippet and adds it to the end of the message.

POST /attachments HTTP/1.1
Authorization: Bearer <authorization token>
Content-Type: application/json
Accept: application/vnd.urbanairship+json; version=3

{
   "notification": {
      "alert": "Hi {{ name }}: Thanks for your purchase! {{> signature }}"
   },
   "snippet_references": {
      "snippets": [
         {
            "name": "signature"
         }
      ]
   }
}

See Snippet references object in our API reference for details.

Manage snippets

Go to Content and select Snippets to view a list of your snippets.

  • Your last modified snippet is listed first.
  • You can sort the list by Name, Date Created, or Date Modified.
  • You can search for snippets by name, keyword, or ID.

Duplicate a snippet

You may want to duplicate a snippet as a starting point rather than starting from scratch.

  1. Go to Content and select Snippets.
  2. Click for a snippet.
  3. (Optional) Enter a name and ID for the new snippet. The name and ID are prefilled with “[original snippet name] copy” and “[original snippet ID]_copy”.
  4. Click Continue.
  5. Edit as you would a new snippet.
  6. Click Save snippet.

Edit a snippet

Snippets are evaluated at send time; if you schedule a message that contains a snippet and then edit that snippet, the scheduled message automatically uses the updated snippet content. “Scheduled” includes recurring messages.

  1. Go to Content and select Snippets.
  2. Click for a snippet.
  3. Edit as you would a new snippet. Click edit next to the snippet name to edit its name and keywords.
  4. Click Save snippet.

Delete a snippet

 Warning

Deleting a snippet that is in use may impact messaging.

  1. Go to Content and select Snippets.
  2. Click for a snippet.