Template with photo galleries and subfolders

Hello all,
I am using 2 slider galleries on the home page. The images are located in subfolders “homeSliderA” and " homeSliderB". Displaying the images in the blueprint works fine with this code:

      homeSliderA:
        label: "Slider 1"
        type: files
        info: "{{ file.dimensions }} px ({{ file.niceSize }})"
        parent: page.children.find("homeSlider")

      homeSliderB:
        label: "Slider 2
        type: files
        info: "{{ file.dimensions }} px ({{ file.niceSize }})"
        parent: page.children.find("homeCategories")

Since I’m using the subfolders, the PHP code in the template doesn’t work anymore because I don’t know how to access the subfolders. How do I need to adjust my PHP code in the template?

<?php
$files = $page->files()->shuffle();
foreach ($files as $file): ?>
<div class="carousel-item <?= $file->is($files->first()) ? 'active' : '' ?>"><img src="<?= $file->url() ?>" alt="" /></div>
<?php endforeach ?>

Thanks a lot for your support!

You have to grab the files from the subpages, not from the current page in this case.

$filesA = $page->find('homeSlider')->files();
// same for the other page.

But don’t use camelCase for page names.

1 Like

Thank you very much for your quick help. I’m sure there will be more questions on other topics until I’m familiar with Kirby’s features and functionality.

It might be worth noting that instead of putting the files into subpages, you could separate them by template, while keeping them in the home page folder. Unless you just want to keep the home folder clean or have the same image in multiple sliders.

     homeSliderA:
        label: "Slider 1"
        type: files
        template: slider-a
        info: "{{ file.dimensions }} px ({{ file.niceSize }})"


      homeSliderB:
        label: "Slider 2
        type: files
        template: slider-b
        info: "{{ file.dimensions }} px ({{ file.niceSize }})"

In the Blueprint/Panel I created separate fields for the two sliders. The first slider can contain any number of images.
The second slider contains cover images for a slider that contains selected navigation topics. This would be my next major build site, but for which I am currently using a different static solution. Here the topic is still too complex for me. I found an approach in this topic, but the implementation would cost me too much time and deeper knowledge with Kirby.

I thought homeSliderA and homeSliderB were sections, because the files field doesn’t have a parent property?