<?php
// fetch the child page into a variable and make sure it exists, then also check if it has images
if (($p = $page->children()->find('project-01')) && $p->hasImages()) : ?>
<div class="swiper-container">
<div class="swiper-wrapper">
<?php foreach($p->images() as $file): ?>
<figure class="swiper-slide">
<img src="<?= $file->url() ?>" alt="<?= $file->alt() ?>">
<figcaption><?= $file->caption() ?></figcaption>
</figure>
<?php endforeach ?>
</div>
<div class="swiper-pagination"></div>
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
</div>
<?php endif ?>
But in the title it says you want to fetch images from multiple subfolders, here we have only one? So I have a feeling there is some context missing…
Thanks, texnixe,
Yeah, i will list multiple projects on a single-page site. Images come from folders with a serial number: project-01, project-02, project-03, etc.
But it doesn’t work. I went back to adding the swiper-container element. How could i change the “project-01” into something more automatic, like, following the order of the folders that are there? I’m not sure if i’m being clear… Basically i have this folder structure with images inside of each folder:
(Assuming we are in the home.php template and calling the snippet)
Note that if you only put the swiper-container into the snippet, you would have to pass the $child variable to the snippet, like explained in my next post.
This cannot work, because $p is not known inside the snippet, you would have to pass it to the snippet snippet('gallery', ['p' => $p]). But for you use case, what I posted above would be more useful anyway.
Oh, sorry for the code screenshot! Yeah, i’m pulling the text content from home.txt, where i have the whole content, i have fields like so: project01, project02, project03, etc.
Rendered, i’d have text and the sliding gallery after, for each project.
It’s a single page site, so my first thought was having all content in one file, the home.txt. But now with the images organized in folders, it makes more sense to have a txt content file for each project. I tested it this way and it works. I do lose the ability to edit everything in one file, but now it’s more organized.