Accessing the current page object information in a kirbytag?

I’m trying to create a basic kirbytag for my website that allows our editors to input a comma-delimited list of images uploaded to a Kirby post. I’m running into a small snag where I can’t figure out how to get the current page information so I can link to the file path of the files (as dragging the file only gives the file name itself).

Here’s the code:

kirbytext::$tags['gallery'] = array(
    'html' => function($tag) {
        // variables
        $images = explode(',', $tag->attr('gallery'));
        $structure = '<div class="photoswipe-gallery"><div class="row">';
        // add the images to the gallery HTML structure
        foreach($images as $image) {            
            $structure .= '<figure class="col-xs-12 col-sm-4"><a href="/resources/images/review/screenshot_1.png" data-size="1920x1080"><img class="img-thumbnail" src="/resources/images/review/screenshot_1.png" alt="" /></a></figure>';
        $structure .= '</div></div>';
        return $structure;

And here’s an instance of how the tag works:

(gallery: screenshot_1.png,screenshot_2.png,screenshot_3.png)

Any ideas?

Managed to figure this out, in case anyone needs to use this in the future it’s under the Accessing the current page section in:

Must have accidentally missed it when going through that section initially, I guess.

(Of course, this assumes you only need to access the current page. If it’s another page, then that’s another story entirely.)

You can access the file with $tag->file().

In any case you should check if the image exists, listing image names in a tag is quite error prone. It would probably be better pull in images from subpages, so the user only has to reference the name of the subpage and all images from that subpage are fetched automatically.