Error when fetching all files / images / etc... with $site->index()

I have a strange situation;

I want to fetch all images, used in my site.

echo $site->index()->files();

This code will output something like this;

G:\xampp\htdocs\_kirby\logo-flow\content\1-ontwerp\ontwerp_a_1.png
G:\xampp\htdocs\_kirby\logo-flow\content\1-ontwerp\ontwerp_a_2.png
G:\xampp\htdocs\_kirby\logo-flow\content\1-ontwerp\ontwerp_b_1.png
G:\xampp\htdocs\_kirby\logo-flow\content\6-site\site_c.png
G:\xampp\htdocs\_kirby\logo-flow\content\home\avatar.png```

As you can see, there are both images (**png**) and documents (**pdf**) in it.

But when I specify the content-type like this, nothing is returned at all;

```echo $site->index()->images();```

```echo $site->index()->documents();```

I can fetch all images / documents at site-level, like this;

```echo $site->images();```

```echo $site->documents();```

That works, but I want **all** files / documents / etc... not **only** the ones, placed in the root of ```content```.

I tested this in a 2.3 beta, so I guess it does not work in 2.2.3 yet; you can do the following, however:

$count_images = $site->index()->files()->filterBy('type', 'image')->count();
$count_files = $site->index()->files()->filterBy('type', 'document')->count();
1 Like

That’s a cool work-a-round!

I think the previous code wasn’t available in 2.2.3 yet (I’m working with the stable release only).

Kirby - At a Glance [widget]

I used the code for a widget, which is now updated on GitHub as well.

Thanks again!