Adding data attributes to kirbytext img links

Hey guys,

I’m new to Kirby CMS and and a PHP newbie. I love Kirby and I’m using it to build my portfolio. What I wanna do is, create a gallery on my case study page and I’m trying to do it as simple as possible: using the “textarea” field. All I do is I add images via the syntax (image: preview.jpg class: thumb link: preview.jpg). Now I’d like to use the Lightbox plugin, but to make this work my link needs a “data-lightbox” attribute so I can get something like this:

(image: preview.png class: thumb link: preview.png data-lightbox: preview)

which would render

<figure class="thumb"><a href="..." data-lightbox="preview"> etc.

How could I add this attribute?

Would highly appreciate any insight to where to get started/look.

Thanks a lot!

The best way to achieve your function would be to create a custom kirbytag, which generates all the html you want.

How to create such a kirbytag is described very well in the docs: create a custom kirbytag
And you can take a look at the original image kirbytag in the Kirby repo.

As I know, there is no possibility to “extend” the functionality of a kirbytext filter, because the filters are stored as arrays, not classes. So you have to copy-paste the default kirbytext filter and add you function to that.

The easiest way would be to actually overwrite the existing image kirbytag, so that you could still drag and drop images from the sidebar.

However, I wouldn’t use a different method to create an image gallery, e.g. a structure field, or the gallery field.

Cheers @jbeyerstedt and @texnixe although I went a different way for building my gallery. Since I don’t need a lot of images displayed, I used simple Image fields instead.