# Liquid templates

<YouTube id="A7l1_gK5yOA" playlabel="Youtube Video: Learn how to use content templates in Customer journeys"/>


Liquid templates significantly broaden Pushwoosh’s personalization capabilities by implementing sophisticated logic in addition to regular[ Dynamic Content](/product/personalization/dynamic-content/) usage.

Message personalization in Pushwoosh is based on [Tags (user data)](/product/audience-data-and-segmentation/user-data-tags/tags). Pushwoosh offers a variety of [default Tags](/product/audience-data-and-segmentation/user-data-tags/tags#default-tags) and [custom Tags](/product/audience-data-and-segmentation/user-data-tags/tags#custom-tags). Using them, you can specify a user's first name, city, purchase history, etc. to send a more personalized message. For example: `Hi {{First_name}}, thanks for ordering {{item}}`.

Liquid templates add more logic to dynamic content. For instance, if a user's subscription tag contains "free," you can send them a message: “Grab your 10% discount.”

Modifying the message content according to users' IDs, behaviors, and preferences is the most efficient way to increase relevance and get more impressive results from your marketing campaigns.

## Syntax

Content templates based on [Liquid by Shopify](https://shopify.github.io/liquid/) use a combination of [**tags**](#tags), [**objects**](#objects), and [**filters**](#undefined) to load dynamic content. Content templates allow you to access certain variables from within a template and output their data without having to know anything about the data itself.

<Aside type="note">
To learn more about the syntax, please refer to [Liquid documentation](https://shopify.github.io/liquid/basics/introduction/).
</Aside>

### Objects

`objects` define the content that will be displayed to a user. `objects` should be enclosed in double curly braces: `{{ }}`

For example, when personalizing a message, send `{{Name}}` in its body to add the users' names to the message's content. The user's name (Name tag value) will replace the Liquid object in a message the user will see.

<Tabs>
<TabItem label="Input">
```
Hi {{Name}}! We're glad you're back!
```
</TabItem>

<TabItem label="Output">
Hi Anna! We're glad you're back!
</TabItem>
</Tabs>

### Tags

`tags` create the logic and control flow for templates. The curly brace percentage delimiters `{%` and `%}` and the text that they surround do not produce any visible output when the template is rendered. This lets you assign variables and create conditions or loops without showing any of the Liquid logic to a user.

For example, using the `if` tag, you can vary the message's language based on what language is set on user's device:

<Tabs>
  <TabItem label="Input">

```liquid
{% if Language == 'fr' %}
Salut!
{% else %}
Hello!
{% endif %}
````

  </TabItem>

  <TabItem label="Output (fr)">
    Salut!
  </TabItem>

  <TabItem label="Output (es)">
    Hello!
  </TabItem>
</Tabs>


### Tags operators

<table data-header-hidden><thead><tr><th width="189.5" align="center">Operator</th><th>Description</th></tr></thead><tbody><tr><td align="center"><code>==</code></td><td>equals</td></tr><tr><td align="center"><code>!=</code></td><td>does not equal</td></tr><tr><td align="center"><code>></code></td><td>greater than</td></tr><tr><td align="center"><code>&#x3C;</code></td><td>less than</td></tr><tr><td align="center"><code>>=</code></td><td>greater than or equal to</td></tr><tr><td align="center"><code>&#x3C;=</code></td><td>less than or equal to</td></tr><tr><td align="center"><code>or</code></td><td>logical or</td></tr><tr><td align="center"><code>and</code></td><td>logical and</td></tr><tr><td align="center"><code>contains</code></td><td>checks for the presence of a substring inside a string or array of strings</td></tr></tbody></table>

<Aside type="note">
In tags with more than one `and` or `or` operator, operators are checked in order _from right to left_. You cannot change the order of operations using parentheses — parentheses are invalid characters in Liquid and will prevent your tags from working.
</Aside>

### Filters

`filters` modify the output of a Liquid object or variable. They are used within double curly braces `{{ }}` and variable assignment, and are separated by a pipe character `|`. Multiple filters can be used on one output, and are applied from left to right.


<Tabs>
<TabItem label="Input">

```

{{ Name | capitalize | prepend:"Hello " }}

```

</TabItem>

<TabItem label="Output">

Hello Anna

</TabItem>
</Tabs>



## Liquid templates usage

Liquid templates are available for both messages sent from Control Panel and [API requests](/developer/guides/personalization/liquid-templates#using-liquid-templates-in-messages-sent-via-api).

In Pushwoosh, Liquid templates are applicable to all content fields of any channel message:

* Push notifications
* Emails

To add a Liquid Template to your message, insert it into the message's body. You can do it when working with [push](/product/customer-journey/journey-elements/#push) or [email](/product/customer-journey/journey-elements/#email) elements, directly from the Customer Journey Builder interface.


Go to **Customer Journey Builder** > **Create Campaign** > drag and drop the following elements to your canvas: **Audience-based Entry**, **Push** (or **Email**), and **Exit**. Connect the elements. Then click the **Push** icon, choose **Custom content**, and insert your copy.


To add Liquid logic, use tag values with the following syntax:  

```liquid  
{% if TagName == 'value' %}  
  Content to send in this scenario  
{% else %}  
  Content to send otherwise  
{% endif %}
```
Then click **Apply**.

<video src="/personalization-liquid-templates-1.webm" title="Customer Journey Builder interface showing how to add Liquid template logic with if-else conditions to push notification content" autoplay loop muted playsinline />

Template variables (Pushwoosh Tags) should not contain any spaces and have only alphanumeric values and underscores, e.g., `my_tag` or `myTag` instead of `My Tag`.

[Learn more about Liquid templates in journeys](/product/customer-journey/journey-elements/dynamic-content-and-liquid-templates-in-journeys)

<Aside type="tip">
 You can also use Liquid syntax in `/createMessage` requests to implement Liquid templates. For this, you’ll need assistance from your development team. Share the [Liquid templates guide](/developer/guides/personalization/liquid-templates) with them for detailed guidance.
</Aside>

## Connected content

Connected content is a feature in Liquid templates that allows you to dynamically retrieve and use data from an external source, such as a web service, directly within your email or push notification messages. This feature enables real-time personalization by fetching JSON data from a specified URL and saving it to a variable that can be utilized in your content. 

#### Key use cases

- **Product recommendations**: Display personalized product lists tailored to each user.

- **Promo codes**: Insert unique promo codes generated by a backend service.

#### Prerequisites

* To use Connected Content, you must have your own backend service that generates and provides the required data (e.g., promo codes, product recommendations) based on **User ID, HWID, or custom tags**. Pushwoosh then fetches this data before sending a message.

### Step-by-step implementation guide

<Aside type="caution" icon="setting" title="Developer assistance needed">
You'll need your developer team's help to use Connected content. Share this guide with them to get started.
</Aside>

#### Step 1. Set up backend service 

The backend service should:

* Accept a request containing user-specific parameters (e.g., `userId`). Connected Content supports `UserID`, `HWID`, or any custom tags you’ve set up in your project.  
* Return a JSON response with the required data. This content can then be inserted dynamically into messages

<Aside type="note" title="How it works"> 

The backend service acts as a data provider, responding to HTTP requests with user-specific information. 

1. Pushwoosh sends a request to your backend, passing user-specific identifiers as query parameters.  
2. Your backend processes the request and retrieves the requested data.  
3. Your backend returns a JSON response.  
4. Before sending a message, Pushwoosh fetches the JSON response from the backend service and uses the returned values (e.g., the `code`) in the message content dynamically.

**Example response**

```
{ "code": "SPECIALOFFERFORUSER12345" }
```
</Aside>



#### Step 2. Create a preset with Сonnected content in Pushwoosh
 
1. In the [Push](/product/content/push-presets/) or [Email content editor](/product/content/email-content/drag-and-drop-email-editor/), insert the Connected Content syntax into the message field.

**Example** 

```
{% connected_content http://your-backend-url.com?userId={{ ${userid} }} :save result %}  
```
**Syntax breakdown**
|  |  |
| ----- | ----- |
| `connected_content` | Fetches JSON data from the specified backend URL. |
|    `http://your-backend-url.com` | The backend endpoint that returns required data in JSON format. |
| `userId={{ ${userid} }}` | A dynamic query parameter that passes the user ID to the backend. |
| `:save result` | Stores the fetched JSON response in the result variable for use in Liquid templates |

![Insert the Connected Content syntax](/connectedcontent.webp)

**Authentication (optional)**

If your backend service requires authentication, you can include an API key or token in the Connected Content request to ensure secure access. 

```
{% connected_content http://your-backend-url.com?userId={{ ${userid} }}&auth=YOUR_API_KEY :save result %}  
```

You can also send authentication (or any other) data as HTTP headers using the optional `:headers` parameter — a JSON object of header names and values.

```
{% connected_content http://your-backend-url.com?userId={{ ${userid} }} :headers {"Authorization": "Bearer YOUR_TOKEN", "X-Api-Key": "YOUR_API_KEY"} :save result %}  
```
|  |  |
| ----- | ----- |
| `:headers {...}` | A JSON object of HTTP headers sent with the request, e.g. `Authorization: Bearer <token>`. |

<Aside type="caution" title="Static values only">
`${}` personalization variables work only inside the URL. Values inside `:headers` are static and are not interpolated.
</Aside>

**Using tags in Connected content**

To include custom tags, insert them as query parameters in the **Connected Content** request (`{{ tag_name }}`).

```
{% connected_content http://your-backend-url.com?userId={{ ${userid} }}{{ Language }} :save result %} 
```

2. Next, add the message text incorporating the **retrieved data**, like this:

```

Hey, {{userid}}, grab your personal promo code - {{result.code}} 
```

![Add the message text with the **retrieved data**](/connectedcontent-1.webp)

3. After finalizing the message content and configuring the preset settings, save it for reuse in campaigns.

<video src="/connectedcontent-2.webm" title="Send a message with connected content" autoplay loop muted playsinline />

#### Step 3. Send a message using the configured preset 

Send a message with this preset using the [one-time push](/product/messaging-channels/push-notifications/send-push-notifications/one-time-push/#how-to-send-a-push-notification-using-the-one-time-push-form) or [email form](/product/messaging-channels/emails/sending-emails/send-one-time-emails/) or [customer journey](/product/customer-journey/pushwoosh-journey-overview/). 

<Aside type="caution" title="Important">
If the service returns a status other than HTTP 200 OK, the email or push notification will not be sent. This ensures that your communication only goes out if the necessary data is successfully retrieved.
</Aside>