Liquid Examples

The following collection of liquid syntax is provided as a reference, and is provided as-is. We encourage you to test the liquid syntax throughout the subscription lifecycle. You are responsible for ensuring the code works for your subscriptions, as well as maintaining this syntax code for the future. Any modifications you make to this code, or modifications you make to code in similar sections, are your responsibility.

Capitilization of names

In the following snippet, there is no need to include {{name}} in the body of the email. The snippet below will pull in the first name only of the subscriber.

{% assign nameparts = name | split: ' ' %}
{% capture titlecase %}{% for word in nameparts %}{{ word | downcase | capitalize }}{% endfor %}{% endcapture %}{{ titlecase }}

Display tax in receipt

{{payment.amount_in_cents | minus: product.price_in_cents | times: 0.001 }}

Replace commas in currency

{{ payment.amount | replace:',','.' }}

Display last 4 digits of a credit card

{{ payment_profile.masked_card_number | remove: "X"}}

Specify text based on subscription payment method

This example specifies a set of text to be delivered to a subscriber if they are on an automatic-based payment method, versus an invoice-based payment method. We find this is a great example to be used in receipts!

Dear {{name}}
[Your email content here.]
{% if subscription.payment_collection_method == "automatic" %}
Text for automatic-based subscriber.
{% elsif subscription.payment_collection_method == "invoice" %}
Text for invoice-based subscriber.
{% endif %}
Cheers,
{{merchant_name}}

Specify text based on product

{% if product.handle =="[REPLACE_WITH_product_handle]" %}

Here is the text that your subscriber should see if they purchase this product with the above and below syntax.

{% endif %}

Specify text based on multiple products

{% if product.handle == "[REPLACE_WITH_product_handle]" or product.handle == "[REPLACE_WITH_product_handle]" or product.handle == "[REPLACE_WITH_product_handle]" or  product.handle =="[REPLACE_WITH_product_handle]" %}

Here is the text that your Subscriber should see if they purchase any of the above products. Be sure to end the if statement below this line.

{% endif %}

To link to a url, surround the text with angle brackets:

<https://example.com/my_page> or <{{subscription.billing_portal_management_url}}>

If you would like to locate our website, please click [here][1] to speak with one of our experts.

[1]: http://www.example.com