For the convenience of the editors, I’m overriding the Kirby image tag: Images in Text are automatically scaled down in 2 sizes, additional HTML for lazyloading is being generated, all is well.
Here’s the working approach:
opening kirby/extensions/tags.php and copying the whole code under //image tag in a custom php file under site/tags.
building new image paths vars via thumb() handling of $file = $tag->file($url);
shoving this into the image builder function which in turn returns a different <img> object.
Now obviously, this is not hacking core but feels pretty rough anyway – is there a less aggressive solution; say by overriding the image builder only?
Or am I missing another functionality and would be better off with a post/preprocessing plugin or some sort of meta-template?
What you did is actually a good way of overriding core tags. Since the image tag (and every other tag) is one complex function, you can’t replace or change only parts of it, so implementing your own makes sense.
Note that this has additional modifications like a different caption fallback and a ratio checker. But the basic logic goes like this: Create new tag (I called it figure.php) under /site/tags and start overriding.
Steps taken:
scale image (note that I generate different scales depending on the ratio; no need to be that complicated)
I kept the original $_image() function to use in a <noscript> fallback and created a second $_imageLazy() one to handle the new image tag.
Those are glued together in the last part; the Kirby toolkit supplies a jQuery-like syntax to generate HTML elements (they are called “bricks”) which is pretty easy to use.