New liquid filters, sending files via API calls
September 20, 2018
In this release notes we will focus on new liquid filters, fixed filter and one new feature.
NEW
assign_to_hash_key filter
This filter allows you to add new key-value pairs into existing hash.
Example:
{% assign accountants = "Angela,Kevin,Oscar" | split: "," %}
{% assign management = "David,Jan,Michael" | split: "," %}
{% assign company = '{}' | to_hash %}
{% assign company = company | assign_to_hash_key: "name", "Dunder Mifflin" %}
{% assign company = company | assign_to_hash_key: "accountants", accountants %}
{% assign company = company | assign_to_hash_key: "management", management %}
{{ company }}
Result:
{"name"=>"Dunder Mifflin", "accountants"=>["Angela", "Kevin", "Oscar"], "management"=>["David", "Jan", "Michael"]}
sanitize filter
This filter allows you to sanitize user input before rendering it and at the same time decide which attributes should not be sanitized.
Example:
{% capture link %}
<a href="javascript:prompt(1)" target="_blank">Link</a>
{% endcapture %}
{{ link | sanitize }} => <a href="">Link</a>
{% assign whitelist_attributes = 'target' | split: '|' %}
{{ link | sanitize: whitelist_attributes }}
Result:
<a href="" target="_blank">Link</a>
useragent filter
There was a community request to make it easier to access useragent and parse it, so here it is.
You can access useragent string (as you normally could in the past)
This filter takes useragent string as an input and returns object with parsed data about it.
Example:
{{ context.headers.HTTP_USER_AGENT | useragent }}
You can use json
filter for readability:
{{ context.headers.HTTP_USER_AGENT | useragent | json }}
FIXED
random_string filter
This filter was returning string that was longer than expected. Now it returns string of length that you want.
Example:
{{ 10 | random_string }} => '6a1e7e2629'
{{ 2 | random_string }} => '8b'
IMPROVED
Binary files over API call notifications
You have the possibility to send binary files in API call. This might be useful when integrating your system with external APIs that require additional data from your users, for example photo.
Read guide Sending a Binary File Using an API Call Notification to learn more.