How to check if the Entry field type relation is empty in antlers? #8705
-
I have a collection called Products Products has a Entry field type relation
In my antlers template for the product collection:
If the Product collection has related categories then the title is of the category title, if there are no related categories then the title is of the product. Categories always evaluates to true even if there are no relations. Hence the above outputs the product title if there are no related categories How can i loop the related categories alway as an array or at least check if there are no related categories? Do i need to use something like this to check the raw value first? is_empty modifier doesn't seem to help. dumping out $categories when there are no relations shows the Statamic\Fields\Value instance with a raw value of null. dumping out $categories when there are relations shows the Statamic\Fields\Value instance with a raw value with the array of related entry ids. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Beta Was this translation helpful? Give feedback.
{{ if (categories | count) > 0 }}
should work for this