[英]How can I conditionally show a section based on if a filtered array would show items?
I'm using Document Generation and have used filtering in lists like so:我正在使用文档生成并在列表中使用过滤,如下所示:
{% repeating-section cats[weight > 5] %}
This will loop over a cats array and only show items where the weight property is over 5. This works fine, but I'm using it in a "section" with an intro and I want to hide the entire section if that particular array is empty.这将遍历 cat 数组,并且仅显示 weight 属性超过 5 的项目。这很好用,但是我在带有介绍的“部分”中使用它,如果该特定数组是,我想隐藏整个部分空的。 How can I use that in a condition?我怎样才能在某种条件下使用它?
Using the JSONata docs, there is a $count
operator.使用JSONata文档,有一个$count
运算符。 This can be used to count the number of items in an array, and include the filter as well.这可用于计算数组中的项目数,并包括过滤器。 So for example:例如:
{% conditional-section expr($count(cats[weight > 5]) > 0) %}
This can be used around the section that includes your list.这可以在包含您的列表的部分周围使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.