Single attachment page on kirby?

Is there a way to make a single page for each file in Kirby?
My problem: I have a project with image galleries but i need a individual share button for each picture… So the first solution that came to my mind was to make a share relative to the “permalink” of the file, but the only URL I could get from Kirby was the file path itself.
I need something like this: http://marcelo-f.com.br/2015/08/atari-teenage-riot/10-3/ (wordpress solution) OR any other ideia for the share issue.
Thanks in advance!

You can use a route together with a template that outputs your image:

Your route catches all urls that end in a number, e.g. www.domain.com/projects/project-a/1 and then loads a template called image.php:

c::set('routes', array(
    array(
        'pattern' => '(:all)/(:num)',
        'action'  => function($uri, $num) {
          tpl::load(kirby()->roots()->templates() . DS . 'image.php', array('uri' => $uri, 'num' => $num),false);
        }
    )
));

In your image.php template you display the image:

<?php 
$page = page($uri);
$image = $page->images()->nth($num);
?>
<img src="<?php echo $image->url(); ?>">

Edit: This is just a basic example. It only works in a permanent way if the number of images or their position does not change. Otherwise you would have to use a meta file for each image that contains a fixed number and you would have to find the image by that meta number.

Instead of using numbers, you could also use the name of the file and generate urls like this:

http://domain.com/projects/project-a/forrest

Then in your route:

c::set('routes', array(
    array(
        'pattern' => 'projects/(:any)/(:any)',
        'action'  => function($uid, $image) {
          tpl::load(kirby()->roots()->templates() . DS . 'image.php', array('uid' => $uid, 'image' => $image), false );
        }
    )
));

And in your image.php

<?php 
$page = page('projects/' . $uid);
if($selected = $page->images()->findBy('name', $image)) : ?>
<img src="<?php echo $selected->url(); ?>">
<?php else : go('error') ; ?>
<?php endif ?>

This is certainly the better/safer way of doing it as far as finding the images is concerned, does not need meta files etc.; but you have to be careful to use a path depth that is not used by other urls within the selected route pattern, otherwise they would be routed to the image template as well. In the example above, it would work with the following structure:

- projects
  -- project a
  -- project-b
  -- ... 

but not with

- projects
 -- project a
    --- abc
    --- xyz
  -- project-b
  -- ... 

Edit: To solve that problem, you could use a pseudo page “image gallery”:

Share link: http://www.domain.com/imagegallery/projects/project-a/forrest

c::set('routes', array(
    array(
        'pattern' => 'imagegallery/(:all)/(:any)',
        'action'  => function($uri, $image) {
          tpl::load(kirby()->roots()->templates() . DS . 'image.php', array('uri' => $uri, 'image' => $image), false );
        }
    )
));
<?php 
$page = page($uri);
if($selected = $page->images()->findBy('name', $image)) : ?>
<img src="<?php echo $selected->url(); ?>">
<?php else : go('error') ; ?>
<?php endif ?>
3 Likes