Blueshift provides some custom Liquid filters that you can use in the messaging templates.
- aes
- any_contains
- base64
- between
- camel_case
- catalog
- escape_url
- hash_algo
- less_than
- money
- more_than
- pow
- regex
- shuffle
- time_zone
aes
This is an AES 256 Encrypt/Decrypt filter. This filter returns a hex encoded AES 256 ciphertext of the input based on a given key, initialization vector and cipher name.
Example for encryption:
{{ 'testuser@getblueshift.com' | aes256_encrypt_v2: '9cc25c7879fc94d5a19eeb8e47573b8423becb608a9a4e9d3c25c20aa7e04357','7bdc922b354cc8fa8d3f2910ba7cc411' }}
Returns the following cipher text:
9be4086dd0f2592273dbe6e0000377ef94ab6aa3573f9344b4abbbbcf47088b7
Example: The Cipher text can also be decrypted as follows:
{{ '9be4086dd0f2592273dbe6e0000377ef94ab6aa3573f9344b4abbbbcf47088b7' | aes256_decrypt_v2: '9cc25c7879fc94d5a19eeb8e47573b8423becb608a9a4e9d3c25c20aa7e04357','7bdc922b354cc8fa8d3f2910ba7cc411' }}
Returns:
testuser@getblueshift.com
Example: The default cipher used is aes-256-cbc, but you can also use aes-256-ecb by passing the cipher name as the 3rd option. Note that the initialization vector is null for ecb mode.
{{ 'hamburger' | aes256_encrypt_v2: '9cc25c7879fc94d5a19eeb8e47573b8423becb608a9a4e9d3c25c20aa7e04357', null, 'aes-256-ecb' }}
Returns:
14d60bd236617adc84e23587f46addd1
any_contains
Check whether a reference string is present in a string or array.
Example:
{{ "ola" | any_contains:"a"}}
Returns: true
Example:
{% assign people = "fred, john, mary" | split: ", " %}
{{ people | any_contains: "m"}}
Returns: true
base_64
Base64 encoding is used to encode binary data for storage or transfer over media that can only deal with ASCII text. This ensures that the data that you send remains intact without modification during the transfer.
The base64_encode filter accepts string data and returns a character string that contains the base64-encoded version of the source string.
The base64_decode filter accepts a base64 encoded character string and returns the base64-decoded version of the encoded string.
base64_encode
Returns the Base64-encoded version of a string.
Example:
{{ "lorem ipsum" | base64_encode }}
Returns:
bG9yZW0gaXBzdW0=
For longer strings, line feeds are added to every 60 encoded characters.
Example:
{{ "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec molestie gravida" | base64_encode}}
Returns:
TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBp c2NpbmcgZWxpdC4gRG9uZWMgbW9sZXN0aWUgZ3JhdmlkYQ==
base64_strict_encode
Similar to base64_encode except that no line feeds are added.
Example:
{{ "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec molestie gravida" | base64_strict_encode}}
Returns:
TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4KICAgIERvbmVjIG1vbGVzdGllIGdyYXZpZGE=
base64_decode
Returns the Base64-decoded version of an encoded string.
Example:
{{ "bG9yZW0gaXBzdW0=" | base64_decode }}
Returns:
lorem ipsum
For longer strings, new lines are ignored when the string is decoded.
Example:
{{ "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBp c2NpbmcgZWxpdC4gRG9uZWMgbW9sZXN0aWUgZ3JhdmlkYQ==" | base64_decode}}
Returns:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec molestie gravida
base64_strict_decode
Similar to base64_decode but any new lines in the string result in an error.
Example:
{{ "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBp c2NpbmcgZWxpdC4gRG9uZWMgbW9sZXN0aWUgZ3JhdmlkYQ==" | base64_strict_decode}}
Returns:
Liquid error (line 63): invalid base64
between
Checks whether a given number is between 2 numbers.
Example:
{{ 10 | between: 5, 15 }}
Returns: true
Example:
{{ 10 | between: 10, 15 }}
Returns: false
Example:
{{ 10 | between: 5, 10 }}
Returns: false
Example:
{{ 10 | between: 5.9, 10.1 }}
Returns: true
camelcase
Removes underscores and returns the camelcase version of the input string.
Example:
{{ "Foo_bar lorem_ipsum" | camelcase }}
Returns:
FooBar LoremIpsum
catalog
Use the Catalog Liquid function to include item information in your templates without using a recommendation scheme. The Catalog function provides direct access for pulling data from user input, events, related catalogs, and more for specific item ids.
For more information and examples, see Include Catalog without recommendations in templates.
catalog_items | Catalog function to access catalog items. |
product_list | Variable to access a catalog item and its attributes. |
catalog_item_id |
The item_id for the catalog item. This can be a single item, multiple items, or a dynamic variable that represents an array of items. |
Accessing a single item:
{% catalog_items product_list 'item_id1' %}
<p><b>Title:</b> {{product_list[0].title}}</p>
<p><b>Price:</b> {{product_list[0].price}}</p>
<p><b>Description:</b> {{product_list[0].extended_attributes.description}}</p>
Accessing multiple items:
In this example, we are accessing three items. They are assigned to the product_list variable in the form of an array. The first item ‘item_id1’, is referenced as product_list[0], the second item ‘item_id2’ as product_list[1], and so on.
{% catalog_items product_list 'item_id1' ‘item_id2’ ‘item_id3’ %}
<p><b>Title1:</b> {{product_list[0].title}}</p>
<p><b>Price1:</b> {{product_list[0].price}}</p>
<p><b>Description1:</b> {{product_list[0].extended_attributes.description}}</p>
<p><b>Title2:</b> {{product_list[1].title}}</p>
<p><b>Price2:</b> {{product_list[1].price}}</p>
<p><b>Description2:</b> {{product_list[1].extended_attributes.description}}</p>
<p><b>Title3:</b> {{product_list[2].title}}</p>
<p><b>Price3:</b> {{product_list[2].price}}</p>
<p><b>Description3:</b> {{product_list[2].extended_attributes.description}}</p>
You can also use a for loop to access the catalog items:
{% for item in product_list %}
<p><b>Title: {{ item.title }}</b></p>
<p>Price: ${{ item.price }}</p>
<p>Description: {{ item.extended_attributes.description }}</p>
{% endfor %}
escape_url
Escapes URL using the CGI specs.
Example:
{{ "http://google.com/foo?title=My Blog & Your Blog" | escape_url }}
Returns:
http%3A%2F%2Fgoogle.com%2Ffoo%3Ftitle%3DMy+Blog+%26+Your+Blog
Hash algorithm
Use the hash functions to convert a data string into a numeric string of fixed length. For more information, see https://en.wikipedia.org/wiki/HMAC.
sha1:
{{ "lorem ipsum" | sha1 }}
Returns:
bfb7759a67daeb65410490b4d98bb9da7d1ea2ce
sha256:
{{ "lorem ipsum" | sha256 }}
Returns:
5e2bf57d3f40c4b6df69daf1936cb766f832374b4fc0259a7cbff06e2f70f269
md5:
{{ "lorem ipsum" | md5 }}
Returns:
80a751fde577028640c419000e33eba6
hmac_sha1:
{{ "lorem ipsum" | hmac_sha1: "key1" }}
Returns:
fb0d741236de69bafc2512db46e167d12aa39496
hmac_sha256:
{{ "lorem ipsum" | hmac_sha256: "key1" }}
Returns:
39a145e185b544c3b3fe16ee0d07a9e989d6bae7863ef7eb7698fc20196421a5
hmac_sha512:
{{ "lorem ipsum" | hmac_sha512: "key1" }}
Returns:
71c96a916f0c0c9f58ef8e9b87c0e7eff227cf6e07cd126b763adc8d31a4645b770d5854ffebb817abc64160d13561ba52756b3bbc74086d79b3a9d37313ea35
hmac_md5:
{{ "lorem ipsum" | hmac_md5: "key1"}}
Returns:
4dcaaefb69719dcb068ab346242e13c1
base64_encoding:
{{ "lorem ipsum" | b64_enc }}
Returns:
bG9yZW0gaXBzdW0=
base64_decoding:
{{ "bG9yZW0gaXBzdW0=" | b64_dec }}
Returns:
lorem ipsum
less_than
Checks whether a number is less than another number.
Example:
{{ 10 | less_than: 8 }}
Returns: false
Example:
{{ 10 | less_than: 10 }}
Returns: false
Example:
{{ 10 | less_than: 18 }}
Returns: true
money
This filter formats numbers as currency. By default it uses the currency configured in your Account Profile.
The following examples assume that the currency configured for your account is USD.
Example:
{{ 19.99 | money }}
Returns: $ 19.99
Example:
{{ '19.99' | money }}
Returns: $ 19.99
The money filter accepts the following options:
Option | Default Value | Sample Values |
use symbol | true | true, false |
use space | true | true, false |
currency type | The currency is configurable in the Account Profile | "USD", "EUR”, "GBP", "INR", "SGD", "AED", "SEK", "CHF”. |
Example: Use the money filter to override the default account currency with Indian Rupees and eliminate the space between the currency symbol and numerical value.
{{ 19.99 | money: true,false,'INR' }}
Returns: ₹19.99
Use the money filter to output a value without decimals.
Example:
{{ 1000000 | money_without_trailing_zeros : false }}
Returns: 1,000,000
Example:
{{ 1000000 | money_without_trailing_zeros }}
Returns: $ 1,000,000
more_than
Checks whether a number is greater than another number
Example:
{{ 10 | more_than: 8 }}
Returns: true
Example:
{{ 10 | more_than: 10 }}
Returns: false
Example:
{{ 10 | more_than: 18 }}
Returns: false
pow
This Power Math filter returns the input to the exponent power.
Example:
{{ 2 | pow: 3 }}
Returns: 8
Example:
{{ 2 | pow: -3 }}
Returns: 1/8
Example:
{{ -2 | pow: 3 }}
Returns: -8
regex_replace
Searches for a matching segment of the string and replaces the matched string with the given replacement string. It is similar to the Liquid replace filter, except that it accepts regex matches as well. If multiple matches are found, this filter replaces all occurrences with the replacement string.
The following examples show the replace and regex_replace filters.
Example:
{{ "Take my protein pills and put my helmet on" | replace: "my", "your" }}
Returns:
Take your protein pills and put your helmet on
Example:
{{ "Take my protein pills and put my helmet on" | replace: "\smy\s", "your" }}
Returns:
Take my protein pills and put my helmet on
Example:
{{ "Take my protein pills and put my helmet on" | regex_replace: "\smy\s", "-your-" }}
Returns:
Take-your-protein pills and put-your-helmet on
shuffle
Shuffle items in an array.
Example:
{% assign shuffled_products = products | shuffle %}
time_zone
Format ISO 8601 compliant dates into a given timezone. Here's a list of Time Zones this filter supports.
Here are some examples:
Example:
{% assign sign_up_date = "Thu Nov 29 2001 14:33:20 UTC" %}
{{ sign_up_date | time_zone: 'Hong Kong' }}
Returns:
2001-11-29 22:33:20 +0800
Example:
{% assign sign_up_date = "29/11/2001 00:00:00 -0900" %}
{{ sign_up_date | time_zone: 'Hong Kong' }}
Returns:
2001-11-29 17:00:00 +0800
The time_zone filter returns a date and hence the output can be chained with a date filter to format the date value.
Example:
{% assign sign_up_date = "Thu Nov 29 2001 14:33:20 UTC" %}
{{ sign_up_date | time_zone: 'Hong Kong' | date: '%d/%m/%Y %H:%M:%S %Z' }}
Returns:
29/11/2001 22:33:20 HKT
You can also offset time by the hour value passed. In this example, the original time value is offset by -7 hours.
Example:
{% assign sign_up_date = "2015-12-01 10:00" %}
{{ sign_up_date | time_zone: -7 | date: '%d-%m-%Y %H:%M' }}
Returns:
01-12-2015 03:00
Comments
0 comments