使用液体,是否有一种方法可以过滤数组并忽略非匹配项
将液体用于商店。
我想浏览一个值数组,并检查这些值是否与其他值列表匹配。如果它们匹配,我想显示它们。如果它们不匹配,我想忽略它们。
目前,我可以通过查看所有值然后“删除”我不想要单独的值来反向做到这一点,但这是一种可怕的方法。
{% for 'field' in [metafield.key.value] | split: ", " %}
{% if field == 'value 1' or field == 'value 2' or field == 'value 3'%}
<div>
field
</div>
{% else %}
{% continue %}
{% endif %}
Using Liquid for a store.
I want to look through an array of values and check to see if any of those values match another list of values. If they match i want to display them. if they do not match i want to ignore them.
I'm currently able to do it in reverse by looking at all the values then 'remove' the ones i don't want individually but that is a terrible way to do this.
{% for 'field' in [metafield.key.value] | split: ", " %}
{% if field == 'value 1' or field == 'value 2' or field == 'value 3'%}
<div>
field
</div>
{% else %}
{% continue %}
{% endif %}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于未来的疲倦旅行者:
这项工作可能需要调整分裂弦的位置:
for future weary travelers:
this works you may need to adjust where you're splitting the string: