Trying to upgrade a Kirby 2 custom KirbyTag to a plugin for Kirby 3

Hi there,
I had a simple gallery custom KirbyTag in Kirby 2 which pulled images into an article dependent on a checkbox in the image metadata i.e.

(gallery: gallery_one) would fetch all the images which had the ‘gallery_one’ checkbox ticked.

I’m trying to upgrade this to a plugin for Kirby 3 but it keeps falling over. This is my code:


Kirby::plugin('gallery/tag', [
  'tags' => [
        'gallery' => [
            'html' => function($tag) {

              $gallery = $tag->attr('gallery');

              $html  = '<ul class="gallery popup-gallery">';

              foreach($tag->page()->files()->filterBy('gallery', '*=', $gallery) as $image) {
                $html .= '<li class="image">';
                $html .= '<a href="' . $image->url() . '" title="' . $image->caption() .'"><img src="' . $image->crop(400)->url() . '" alt="' . $image->caption() .'" /></a>';
                $html .= '</li>';

              $html .= '</ul>';

              return $html;



The error is ‘Call to a member function files() on null’ in the ‘foreach…’ line. Any pointers in the right direction would be much appreciated.

Eventually I’ll probably upgrade this to a block, but right now I just want to ensure backwards compatibility with the content.

Thanks very much for any suggestions,

Should be


instead of `$tag->page()->files()…

Wonderful, thanks @texnixe!