(液体)检查阵列中的变量

发布于 2025-02-13 13:05:05 字数 254 浏览 1 评论 0原文

我希望找到当前收集页面的标题是否存在于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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

前事休说 2025-02-20 13:05:05

因此,我发现了为什么这不起作用的原因,对于其他遇到此

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 &, while collection.title renders it as &. Therefore, if you try to compare the names it won't work.

The solution is doing | escape to only shop.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.

决绝 2025-02-20 13:05:05

您可以将代码重写为:

{% for vendor in shop.vendors %}
  {% if vendor == collection.title %}
     <div> display content in here if condition is not met </div>    
  {% endif %}
{% endfor %}

You can rewrite your code as:

{% for vendor in shop.vendors %}
  {% if vendor == collection.title %}
     <div> display content in here if condition is not met </div>    
  {% endif %}
{% endfor %}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文