Check if collection is filled

Hey there,

how do I check if a collection has at least one item? (which I guess also applies to structure fields?!)

You can use count(). It returns false if there is no item in the collection.

For example:

<?php
if($page->structureField()->structure()->count()):
  // do your thing
endif;
1 Like