A template for each image in a folder?

hi kirbyans, i have one question:
Is it possible to have a page for each image in a one folder structure.

gallery folder

  • image a
  • image b
  • image c

http://example.com/gallery/image-a
shows just this exact image with a template so there would be possible to nav next/prev page.

maybe i could do it with one page and a script but it not my prefered solution.
any idea is welcome… thanks

Check out this post: Using pagination with image collection

Alternatively, you can probably work with a route that loads a snippet and passes the correct image to the snippet.

If you want to have a different page for each image in the gallery, the basic solution is to have one folder for each image:

content/
    gallery-name/
        gallery.php
        image1/
            image.txt
            image.jpg
        image2/
            image.txt
            image.jpg

But the extra folders and the many image.txt (used to tell Kirby to render this page using a corresponding image.php template) can be a bit repetitive.

Another solution is to keep all images as files in a single page (and folder):

content/
    gallery-name/
        gallery.php
        image1.jpg
        image2.jpg

and then you have two choices:

  1. If URLs like /gallery-name?image=1 are okay with you, you could use a single template (gallery.php) to show the gallery overview (for the /gallery-name URL) or a single image from the gallery (for /gallery-name?image=x URLs).

  2. If you would rather have clean URLs like /gallery-name for the overview and /gallery-name/1 for a single image, you can do that by using a “route” as suggested by @texnixe. This allows you to tell Kirby that requests matching certain URL patterns should trigger a PHP function, and in that function you can decide to find and return a page, render a template, etc. It’s like a (series of) page(s) without having to create actual folders in the content directory.

Let us know, which of the options you prefer and if you need any further help with setting this up.

Thank you very much for your inputs. I use textnixes suggestion with the pagination - it works well.
Maybe a bit hacky but its ok for me with the urls: /gallery/page:1

/gallery/album.txt (album.php)

<?php
  $images = new Collection();
  foreach ($page->images()->sortBy('sort', 'asc') as $i) {
      $images->data[] = $i;
  }
  $images = $images->paginate(1);
  $pagination = $images->pagination();
?>
<?php foreach ($images as $image): ?>
  <?php echo thumb($image, array('width' => 320, 'quality' => 70)); ?>
<?php endforeach ?>

/gallery/index/index.txt (index.php)

<?php
  $a = 1;
  foreach($page->parent()->images()->sortBy('sort', 'asc') as $img): ?>
    <a title="<?php echo html($img->caption()) ?>" href="<?php echo $page->parent()->url() ?>/page:<?php echo $a ?>">
     <img src="<?php echo thumb($img, array('width' => 132,'height' => 132, 'crop' => true), false) ?>" alt="<?php echo $img->filename() ?>" title="<?php echo $img->filename() ?>" >
    </a>
  <?php $a++; ?>
<?php endforeach ?>