Kirbytext Inline Gallery?

Apologizes in advanced for what might be a really simple question. I’m trying to create my own inline slide show/gallery kirbytext tag but I’m having trouble outputting multiple values for a single attribute.

If someone writes the following in the text file…

(gallery: file01.jpg, file02.jpg)

I’m able to output “file02.jpg” but nothing else. Below is the code that I’m using (based off of the downloads.php example from the documentation).

<?php
kirbytext::$tags['gallery'] = array(
     'html' => function($tag) {
      foreach ($tag->files() as $img) {
          $html .= '<li>';
          $html .= '<a href="' . $img . '">' . $img . '</a>';
          $html .= '</li>';
       }
   
      return $html;
   
    }
);

Try something like:

  1. $tag->attr('gallery') actually gets what’s after the colon in (gallery: THIS)
  2. ->split(', ') splits that one string up, so you get your filenames in an array
  3. with $tag->file(FILENAME) you can retrieve the image and from there on use the standard image/file methods with it, e.g. ->url()

Hm, that didn’t seem to work but knowing that split() outputs an array helps a ton. I’ll keep trying, thanks!

So it seems split() is breaking it, is it possible that’s not valid for kirbytext tags?

Um maybe… you could try this instead: http://getkirby.com/docs/toolkit/api/str/split

Hi

Would anyone be able to tell me how this was solved? It is driving me insane!

TIA

Jason

It is working. Look at my gallery tag at this plugin.

But in the current version I don’t use the tag place. I implement the function in the pre block.
In the past I released it at the tag part.

Here the commit-Level with the old API.

And here the solution for the splitting (‘image_gallery’ is the tag name).

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

The result is a array with the images.

By the way, I should look at the toolkit. Really nice features. :wink:

2 Likes