I have been trying to compute and set a flow variable using liquid template syntax. What I need to do is filter an array to remove a value from it and set that into a variable.
First I tried using where
expression but it's not documented in Tiwlio docs, so my guess is it's not supported.
I assign body
& options
but in Studio Flow these would already defined values
Example code:
{% assign body = "Test2" %}
{% assign options = "Test,Test2,Test3" | split: "," %}
{% assign options_filtered = "" | split: "" %}
{{options_filtered | where: body }}
Since the above attempt was unuseful, I tried populating the array manually and then joining it into a string
Example code:
{% assign body = "Test2" %}
{% assign options = "Test,Test2,Test3" | split: "," %}
{% assign options_filtered = "" | split: "" %}
{% for item in options %}
{% if item != body %}
{% assign options_filtered = options_filtered | concat: item %}
{% endif %}
{% endfor %}
{{options_filtered | join: ","}}
This approach was unsuccessful as well, I just get errors that returned value is not a JSON.
What I ended up doing is creating a Twilio Function where I pass a stringified array and value to filter out, but I would still like to avoid using the function if possible.
Any ideas and suggestions are welcome.
Thanks!
@philnash
Well, this sort of works if the items in array all all different, but I have a problem if
body
is s substring in an option, like for example:Output would be