(液体)检查阵列中的变量
我希望找到当前收集页面的标题是否存在于Shop的数组中。供应商并仅在数组中不存在集合页面标题时显示DIV。从文档看来我应该能够做到这一点,但它不起作用?
{%- unless shop.vendors contains collection.title -%}
<div> display content in here if condition is not met </div>
{%- endunless -%}
I’m looking to find if the title of the current collection page exists inside the array of shop.vendors and display a div only if the collection page title does not exist in the array. From the documentation it seems like I should be able to do this but it doesn't work?
{%- unless shop.vendors contains collection.title -%}
<div> display content in here if condition is not met </div>
{%- endunless -%}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因此,我发现了为什么这不起作用的原因,对于其他遇到此
shop.dendors
的其他人呈现为&amp; amp
而不是&amp ;
,而collection.title
将其呈现为&amp;
。因此,如果您尝试比较名称,则无法使用。解决方案正在执行
|逃脱
shop.dendors
这样,它们的格式相同,然后比较可以使用。我也做了|删除
以完全消除及以下的&ampers,因为在我的情况下,在名称比较中并不是严格需要的。So I've found out why this wasn't working, for anyone else who comes across this
shop.vendors
renders an ampersand as&
rather than&
, whilecollection.title
renders it as&
. Therefore, if you try to compare the names it won't work.The solution is doing
| escape
to onlyshop.vendors
so they're formatted the same, then the comparison will work. I also did| remove
to get rid of the ampersand entirely as it's not strictly needed in the name comparison in my case.您可以将代码重写为:
You can rewrite your code as: