Help with Bootstrap Inline Gallery through Kirbytext Tags

I am by no means a coder but last year I “hacked” together a Kirby 1 site from numerous blog and forum posts. For one reason or another it was never deployed but I have now returned to it and am in the process of updating it for Kirby 2 in the hope of getting it up and running soon.

I have unfortunately hit a wall with regard to the new implementation of Kirbytext tags. I wish to update my inline gallery which I had previously put together from many helpful posts (many of which I can’t now find as the K1 form is gone!).

The gallery worked so in the content I could add (gallery: image1.jpg, image2.jpg) and a Bootstrap slider would display the images.

Below is what I currently have from Kirby 1

Kirbytext Extended:

<?php
 
class kirbytextExtended extends kirbytext {
function __construct($text, $markdown=true) {
parent::__construct($text, $markdown);
// define custom tags
$this->addTags('gallery');
}
 
function gallery($params) {
global $site;
$page = $site->pages()->active();
$images = str::split($params['gallery']);
$result = array();
if(empty($images)) return false;
if($page->images()->count() == 0) return false;
foreach($images as $img) {
$imgObj = $page->images()->find($img);
if($imgObj) $result[] = $imgObj;
}
if(empty($result)) return false;
return snippet('gallery', array('images' => $result), true);
}
 
}
 
?>

Snippet:

<div id="carousel-gallery" class="carousel">

  <div class="carousel-inner">
    <?php $n=0; foreach($images as $image): $n++; ?>
    <div class="item<?php if($n==1) echo ' active' ?>">
      <img src="<?php echo $image->url() ?>" alt="<?php echo html($image->title()) ?>" />
      <div class="carousel-caption">
        <?php echo kirbytext($image->caption()) ?>
      </div>
    </div>
    <?php endforeach ?>
  </div>

  <a class="carousel-control left" href="#carousel-gallery" data-slide="prev">&lsaquo;</a>
  <a class="carousel-control right" href="#carousel-gallery" data-slide="next">&rsaquo;</a>

</div>

<script>
  $(function() {
    $('#carousel').carousel('pause');
  });
</script>

If anyone has the time would it be possible to point me in the correct direction to convert this to Kirby 2’s “tag” functionality.

Many thanks in advance and thank you to everyone whose posts I have used previously.

Yours

Jason

Maybe having a look at this plugin will help you with your own implementation: https://github.com/distantnative/kirby-collage/blob/master/site/plugins/gallery/gallery.php

Has anyone worked on this in the past 2 years? It seems like a really useful bit of code, and the gallery plugin referenced isn’t on github anymore, so … Bueller? Bueller?

Here are two alternatives: