Snippets

Snippets are reusable pieces 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 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.

 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 In-App Automation.

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 HandlebarsAirship’s message personalization syntax using double curly braces, more commonly known as {{handlebars}}. Use handlebars to insert variables and conditional logic in messages and templates. 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 handlebar syntax — {{merge_field}}. and Dynamic ContentVariable message content using handlebar syntax that you populate at send time. Use dynamic content to personalize messages for each member of your audience. to personalize messages for each individual member of your audience.

When adding or editing content that contains handlebar syntax, you can enter JSON sample data representing a member of your audience to test any Dynamic ContentVariable message content using handlebar syntax that you populate at send time. Use dynamic content to personalize messages for each member of your audience. statements, without having to send test messages.

Create a snippet

You can create a maximum of 200 snippets per project.

  1. Go to Messages » Templates » 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. 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. (Personalized content only) Enable Sample data and enter a JSON object representing a member of your audience. The message preview updates to show what your message will look like when populated with data.
    4. Click Done.
  6. Click Save snippet when you are done adding content.

Insert a snippet

You can insert a snippet anywhere that supports HandlebarsAirship’s message personalization syntax using double curly braces, more commonly known as {{handlebars}}. Use handlebars to insert variables and conditional logic in messages and templates. by entering its ID in the format {{>snippet_ID}}.

When using the Interactive EditorA tool for creating content for landing pages, Message Center, and email. 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 Messages » Templates » 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 or ID.

Duplicate a snippet

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

  1. Go to Messages » Templates » 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

If you schedule a message that contains a snippet and then edit that snippet, the scheduled message does not automatically use the updated snippet content. Airship uses the snippet as it existed when you created the message unless you manually update the message. “Scheduled” includes recurring messages.

  1. Go to Messages » Templates » Snippets.
  2. Click   for a snippet.
  3. Edit as you would a new snippet.
  4. Click Save snippet.
  5. (Optional) Update scheduled and recurring messages that use the edited snippet.
    1. Go to Messages » Messages Overview.
    2. Select the Scheduled or Ongoing view.
    3. Click   for the message you want to update.
    4. Click Review & Schedule in the header, then click Schedule Message. You do not need to change the message itself. The message will be updated to reflect the changes made to the edited snippet.

Delete a snippet

 Warning

Deleting a snippet that is in use may impact messaging.

  1. Go to Messages » Templates » Snippets.
  2. Click   for a snippet.