[英]Twilio studio variable
I have been trying to compute and set a flow variable using liquid template syntax.我一直在尝试使用 liquid 模板语法计算和设置流变量。 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.首先,我尝试使用
where
表达式,但它没有记录在 Tiwlio 文档中,所以我猜它不受支持。
I assign body
& options
but in Studio Flow these would already defined values我分配
body
和options
,但在 Studio Flow 中,这些已经定义了值
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.这种方法也不成功,我只是得到返回值不是 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.我最终做的是创建一个 Twilio Function,我在其中传递一个字符串化数组和值以过滤掉,但我仍然希望尽可能避免使用 function。
Any ideas and suggestions are welcome.欢迎任何想法和建议。
Thanks!谢谢!
I found this worked:我发现这有效:
{% assign body = "Test2" %}
{% assign options = "Test,Test2,Test3" | split: "," %}
{% assign options_filtered = options | remove: body | join: "," %}
{{ options_filtered }}
Make sure you are only using options documented in Twilio's Liquid guide .确保您仅使用Twilio 的 Liquid 指南中记录的选项。 For example,
concat
and where
are not present.例如,
concat
和where
不存在。 remove
is the filter you need to filter a list. remove
是过滤列表所需的过滤器。
@philnash @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:好吧,如果数组中的项目都不同,这种方法就可以工作,但是如果
body
在一个选项中是 s substring,我就会遇到问题,例如:
{% assign body = "About" %}
{% assign options = "About App,About Company,About Company Services" | split: "," %}
{% assign options_filtered = options | remove_first: body | join: "," %}
{{ options_filtered }}
Output would be Output 将是
App,About Company,About Company Services
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.