I’m having trouble counting and displaying the amount of images in a files-field inside a structure-field.
I’m trying the following:
<?php $blogPosts = $page->blogPosts()->toStructure();
foreach($blogPosts->limit(4) as $blogPost):
$postImages = $blogPost->images();
$imageCount = $postImages->count(); ?>
<div id="myElement" data-images="<?= $imageCount ?>">
<!-- ... -->
</div>
<?php endforeach ?>
But I keep getting this exception error:
I have counted files using count()
many times before. Why is it not working here? Does the field behave differently because it is part of a structure-field?