# Personalization

## Personalization

### Personalize emails inline

To personalize the `subject`, `html`, and `text` fields for each recipient, use the [LiquidJS](https://liquidjs.com) templating language. Enclose each variable name in double curly braces (`{{ }}`). For every variable in your content, include a matching key in the `variables` object for each recipient in the `to` array.

To get email messages to render properly, provide a default value for every variable. When a recipient's variables don't contain the corresponding data, the email message displays a generic value.

```bash
curl -X POST 'https://comms.twilio.com/v1/Emails' \
-H 'Content-Type: application/json' \
-d '{
    "from": {
        "address": "support@example.com",
        "name": "Support Team"
    },
    "to": [
        {
            "address": "jane.doe@example.com",
            "variables": {
                "firstName": "Jane",
                "lastName": "Doe"
            }
        },
        {
            "address": "john.doe@example.com",
            "variables": {
                "firstName": "John",
                "lastName": "Doe"
            }
        }
    ],
    "content": {
        "subject": "Hello {{ firstName | default: '\''there'\'' }}",
        "html": "<html><body><p>Hey {{ firstName | default: '\''there'\'' }} {{ lastName }}, your order is ready.</p></body></html>",
        "text": "Hey {{ firstName | default: '\''there'\'' }} {{ lastName }}, your order is ready."
    }
}' \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
```

### Advanced templating

The Email API supports [LiquidJS](https://liquidjs.com) for advanced email templating.

In addition to simple variable replacement, you can use control flow structures like `if` and `unless`. This allows personalization that renders parts of an email for only specific recipients.

```bash
curl -X POST 'https://comms.twilio.com/v1/Emails' \
-H 'Content-Type: application/json' \
-d '{
    "from": {
        "address": "marketing@example.com",
        "name": "Marketing Team"
    },
    "to": [
        {
            "address": "jane.doe@example.com",
            "variables": {
                "firstName": "Jane",
                "plan": "premium"
            }
        },
        {
            "address": "john.doe@example.com",
            "variables": {
                "firstName": "John",
                "plan": "free"
            }
        }
    ],
    "content": {
        "subject": "Your monthly update, {{ firstName | default: '\''there'\'' }}",
        "html": "<html><body><p>Hello {{ firstName | default: '\''there'\'' }}!</p>{% if plan == '\''premium'\'' %}<p>Thank you for being a premium member. Here are your exclusive benefits.</p>{% endif %}</body></html>",
        "text": "Hello {{ firstName | default: '\''there'\'' }}! {% if plan == '\''premium'\'' %}Thank you for being a premium member. Here are your exclusive benefits.{% endif %}"
    }
}' \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
```

## Next steps

* To learn about tracking the status of your email sends, see [Operations and Email Tracking](/docs/email/api/operations-and-email-tracking).
* To view delivery activity in the Console, see [Email logs](/docs/email/logs).
