I’m trying to extend the image Kirbytag and wrap the image in another tag—very simple.
However, the below code results in extra junk. Images get wrapped in the intended <a> tag, but Kirby also generates additional <p> and <br> elements all around where the images are rendered. I can’t find a logic to it. In some places it’s an empty <p> and other times it’s a <p> with an empty <a> inside of it.
It’s almost as if my html is being reinterpreted as Kirbytext and the whitespace is getting re-parsed. Is that possible? Am I missing something really obvious?
"imageLightbox" => [
"html" => function ($tag) use ($originalTag) {
$file = $tag->file($tag->value());
$ratio = $file->ratio();
$result = $originalTag["html"]($tag);
// look for this
$pattern = ["/<figure/i", "/<\/figure>/i"];
// replace with this
$figure = [
'<a class="photoset__photo lightbox__photo" href="' . $file->url() .'"><figure', "</figure></a>",
];
// replace the old image tag
$result = preg_replace($pattern, $figure, $result);
return $result;
},
],