# Snippets

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

<!-- Page description ^^ is first sentence of glossary def for "snippet". -->

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:

* **Company branding** — Create an HTML snippet with your company's colors. When the colors need to be updated, edit the hex values in the snippet.
* **Header and footer blocks** — Create HTML snippets for the headers and footers you use for messages across different channels.
* **Streamline inserting** [external data feeds](https://www.airship.com/docs/reference/glossary/#xdf) — Create a snippet that references an external data feed. Instead of using the longer format and process used to insert a feed, use the shorter snippet format: `{{>snippet_ID}}`.

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 [Handlebars](https://www.airship.com/docs/reference/glossary/#handlebars) and [external data feeds](https://www.airship.com/docs/reference/glossary/#xdf) to insert [merge fields](https://www.airship.com/docs/reference/glossary/#merge_field) and [dynamic content](https://www.airship.com/docs/reference/glossary/#dynamic_content) to personalize messages for each individual member of your audience. The dashboard supports previewing content that contains Handlebars. See [Previewing personalized content](https://www.airship.com/docs/guides/personalization/previewing/).

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:

```html
<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:

```text
{{>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**.
1. Select **Create snippet**.
1. Enter a name and description 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.
1. (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.**
1. (Optional) Add keywords to help organize your snippets. Enter a term in the search field and select from results, or select *Add keyword: [term]*. You can add up to 10 keywords.
1. Select **Continue**.
1. Add your plain text and/or HTML content.
   1. Select **Add **.
   1. Enter your content. The preview updates as you type.
   > **Important:** Do not insert a snippet into another snippet.

   1. Select **Done**.
1. Select **Save snippet** when you are done adding content.

## Insert a snippet

You can insert a snippet anywhere that supports [Handlebars](https://www.airship.com/docs/reference/glossary/#handlebars) by entering its ID in the format `{{>snippet_ID}}`. To get the ID, go to **Content**, then **Snippet**, select the more menu icon () for a snippet, then **Copy ID to clipboard**.

> **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 editor](https://www.airship.com/docs/guides/messaging/editors/interactive/) and pasting or uploading HTML, a snippet is immediately rendered in the preview. If using layouts, you can insert snippets into text or HTML content, but they will not render in the editor. You must select **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.

```http
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](https://www.airship.com/docs/developer/rest-api/ua/schemas/push/#snippetreferences) in our API reference for details.

## Managing snippets

Go to **Content** and select **Snippets** to view the list of snippets in your project. You can search by name, ID, or keyword. Snippets that are used in template content are labeled "In use".

You can manage snippets from two locations:

* **More menu** — Select the more menu icon () for a snippet for the options to edit, duplicate, add to a [Campaign](https://www.airship.com/docs/reference/glossary/#campaign), or delete. Deleting a snippet that is in use may impact messaging.

* **Drawer** — Select **View detail** from the more menu, or select the snippet name, to open a drawer with the same edit and duplicate options as in the more menu, plus the ability to change its name, description, and keywords, and manage its [associated Campaigns](https://www.airship.com/docs/guides/messaging/features/campaigns/#content-assets). The drawer also displays the [external data feeds](https://www.airship.com/docs/reference/glossary/#xdf) used in the snippet and any [templates](https://www.airship.com/docs/guides/personalization/content/templates/) that reference it.

Duplicating makes a copy of the snippet in the current project or in a different project.

> **Note:** When duplicating content to a different project, Airship does not copy segments, attributes, custom events, deep links, subscription lists, Preference Centers, brand guidelines, or Scene settings from the source project. Configure them independently in each project.

To manage keywords for multiple snippets at once, select them in the list, then select **Actions**, and then **Manage keywords**.
