Skip to main content

User Attributes - Liquid Use Cases

This page shows how to use Liquid with user attributes in Blueshift. You'll find examples for greetings, fallbacks, locale-based messaging, booleans, numeric logic, nested attributes, predictive attributes, computed attributes, and safe handling of missing data.

All examples are verified for Blueshift's Liquid syntax and supported filters.

On this page

First name greeting

Insert the user’s first name directly from their profile.

Liquid:

Hi {{ user.firstname }}!

Example data:

{
"user": {
"firstname": "Alex"
}
}

Rendered output: Hi Alex!

First name with fallback

Show a default term when the first name is missing or blank.

Liquid:

Hi {{ user.firstname | default: "there" }}!

Example data:

{
"user": {
"firstname": ""
}
}

Rendered output: Hi there!

Full name assembly

Combine first and last name, and use a safe default when either value is missing.

Liquid:

{% assign first = user.firstname | default: "" %}
{% assign last = user.lastname | default: "" %}
{% assign full = first | append: " " | append: last | strip %}

{{ full | default: "Valued Customer" }}

Example data:

{
"user": {
"firstname": "Alex",
"lastname": "Rivera"
}
}

Rendered output: Alex Rivera

Locale-based messaging

Choose messaging based on the user’s locale field (for example, "en_US", "es_ES", "fr_FR").

Liquid:

{% if user.locale == "es_ES" %}
¡Hola!
{% elsif user.locale == "fr_FR" %}
Bonjour !
{% else %}
Hello!
{% endif %}

{%- comment -%} Alternative using case {%- endcomment -%}
{% case user.locale %}
{% when "es_ES" %}¡Hola!
{% when "fr_FR" %}Bonjour !
{% else %}Hello!
{% endcase %}

Example data:

{
"user": {
"locale": "fr_FR"
}
}

Rendered output: Bonjour !

Boolean attribute logic

Display different content based on a true/false extended attribute.

Liquid:

{% if user.extended_attributes.is_premium %}
Thanks for being a premium member!
{% else %}
Upgrade to unlock premium benefits.
{% endif %}

Example data:

{
"user": {
"extended_attributes": {
"is_premium": true
}
}
}

Rendered output: Thanks for being a premium member!

Numeric attribute logic

Compare numeric attributes such as points, balances, or scores.

Liquid:

{% if user.extended_attributes.points >= 1000 %}
You're a top member!
{% else %}
Keep earning points to unlock top member status.
{% endif %}

{%- comment -%}
Note: In your actual Liquid code, use =.
The code block escapes it as >= for HTML.
{%- endcomment -%}

Example data:

{
"user": {
"extended_attributes": {
"points": 1200
}
}
}

Rendered output: You're a top member!

Nested attributes

Access nested objects stored inside extended attributes (for example, an address object).

Liquid:

{% if user.extended_attributes.address
and user.extended_attributes.address.city %}
We deliver to {{ user.extended_attributes.address.city }}.
{% else %}
Check your delivery address in your profile.
{% endif %}

Example data:

{
"user": {
"extended_attributes": {
"address": {
"city": "Austin"
}
}
}
}

Rendered output: We deliver to Austin.

Predictive attributes

Use predictive attributes such as category affinity to personalize recommendations.

Liquid:

{% if user.predictive_attributes
and user.predictive_attributes.category_affinity %}
We think you'll love {{ user.predictive_attributes.category_affinity[0] }}.
{% endif %}

{%- comment -%}
Legacy path for older accounts:
{{ user_metrics.category_affinity[0] }}
{%- endcomment -%}

Example data:

{
"user": {
"predictive_attributes": {
"category_affinity": [
"Shoes",
"Accessories"
]
}
}
}

Rendered output: We think you'll love Shoes.

Computed attributes

Reference values calculated by computed attributes in your account.

Note: Computed attributes must be configured in your Blueshift account before they are available in Liquid.

Liquid:

Your average order value is ${{ user.computed_attributes.avg_order_value }}.

Example data:

{
"user": {
"computed_attributes": {
"avg_order_value": 82.5
}
}
}

Rendered output: Your average order value is $82.5.

Missing-data fallback pattern

Use safe checks so greetings render cleanly when attributes are blank.

Liquid:

{% if user.firstname == blank %}
Hi there
{% else %}
Hi {{ user.firstname }}
{% endif %}

Example data:

{
"user": {
"firstname": ""
}
}

Rendered output: Hi there

Did this answer your question?