Problem with $page->hasImages()

I moving an installation to Kirby V3 and I have a problem with the $page->hasImages() and even with the $page->hasFiles() method. I have a site with 3 images and both methods returning only one image/file as result. To trace the problem I dumped the inventory of the site and get all three images shown in the output.

<?php echo "trace hasImages: " . $page->hasImages() . "<br>" ?>
<?php echo "trace hasFiles: " . $page->hasfiles() ?>

Output
trace hasImages: 1
trace hasFiles: 1

Inventory dump

Array
(
    [children] => Array
        (
        )

    [files] => Array
        (
            [Verabschiedung1.jpg] => Array
                (
                    [filename] => Verabschiedung1.jpg
                    [extension] => jpg
                    [root] => /Projekte/grundschule-doenberg.de/content/2_aktuelles/2_neuigkeiten/20190131/Verabschiedung1.jpg
                )

            [Verabschiedung2.jpg] => Array
                (
                    [filename] => Verabschiedung2.jpg
                    [extension] => jpg
                    [root] => /Projekte/grundschule-doenberg.de/content/2_aktuelles/2_neuigkeiten/20190131/Verabschiedung2.jpg
                )

            [Verabschiedung3.jpg] => Array
                (
                    [filename] => Verabschiedung3.jpg
                    [extension] => jpg
                    [root] => /Projekte/grundschule-doenberg.de/content/2_aktuelles/2_neuigkeiten/20190131/Verabschiedung3.jpg
                )

        )

    [template] => news
)  

Any suggestions?

As the page can only have images (1) or not have images (0), I believe this output is correct.

You could use $page->images()->count().

You are right, but the reference says these methode returns the number of the images in the folder —> https://getkirby.com/docs/reference/objects/page/has-images

Perhaps a bug in the documentation.

Any method that starts with has or is returns a boolean.

Yes, that is completely wrong, maybe a copy and paste thing. Just fixed.

1 Like