I thought this post would answer my question, but it didn’t quite:
What I need is to automatically add a class to all images that are added to content via the default kirbytag’s
“(image: …)” method.
The closest I have been able to do is to copy the default tag.php (to make a copy that lives in my site/tags folder, that can override the core one) and add a “fallback” class as described in the “How to create custom Kirbytag” documentation.
This means that the class I want automatically added is applied by default, which is great… However, I would like to preserve the ability to add a custom class via the image tag in panel: (image: xxx.jpg class: customclass). Currently, with the fallback method I am using, this means the customclass added in the panel will completely replace the default tag I want all content images to have. So all core CSS properties I have assigned to the default class will not be assigned to images with a customclass.
I simply want the customclass (if added via panel) to override or add certain CSS properties of the default class; not to replace the default class entirely!
Here is what I have done in my copy of tag.php:
//image builder section (commented section name existed in the original tag.php), I have replaced this line of code:
'class' => $class,
with this line of code:
'class' => $tag->attr('class', 'contentimage'),
(“contentimage” is the name of the class I want applied automatically to all the images added via the image tag in panel).
I have experimented with using
but can’t figure out where to fit it into the existing code without throwing breaking errors.
If anyone knows how to do what I need, that would be awesome! Thanks!