Best way to make an inline gallery with a custom kirbytag?

Thanks @texnixe for your help, but that just broke it… When I add that code instead, it is not showing any images whatsoever.

My latest approach has been trying the first of my approaches mentioned in my original question: listing the images inline per gallery. Whenever I called the gallery tag within the panel text, though, it produced every image in the page’s sidebar. I found this suggestion to split them:

$images = explode(",", $tag->attr('image_gallery'));

as described here:
https://forum.getkirby.com/t/kirbytext-inline-gallery/510/7

If I only try to call the names of images, this works to pull just the images that were actually mentioned in the tag! However, I can’t figure out how to get it to to show the images themselves! I tried I have tried adding ->toFile() to either place that $slide appears, but both changes resulted in nothing showing from the fields that the gallery tags were called.

Here is my full code with (without ->toFile() anywhere since it was breaking things):

<?php kirbytext::$tags['gallery'] = array( 'html' => function($tag) { $images = explode(",", $tag->attr('gallery')); foreach ($images as $slide) { $html .= '
  • '; $html .= $slide; $html .= '
  • '; } return $html; } ); Any ideas how I can use the `explode ( ... )` suggestion (or another way) but get images to show instead of text? Thanks so much for all your help with this everyone!