I would like some help with the following. In the Kirby Toolkit, there’s the HTML API which generates tags for common HTML elements. I would like to alter one of them (the tag) so I can use a certain lazy-load plugin.
This is the public static function in the HTML Class in the Toolkit:
public static function img($src, $attr = array()) {
$attr = array_merge(array('src' => $src, 'alt' => pathinfo($src, PATHINFO_FILENAME)), $attr);
return static::tag('img', null, $attr);
}
The only thing I really need to do, is changing the 'src'
in the array_merge(array)
part to 'data-img-src'
. What is the correct way to extend or alter this and where do I put the override, without touching the (in my case: ‘git-submoduled’) Toolkit? Or is it better to create a custom one and if so: how?
On a similar note: I would like to edit the HTML generated by the standard image
tag as well. I’ve found out that I can copy the whole kirbytext::$tags['image']
in a new site/tags/image.php
file, but I only need to change this bit (the $figure->addClass()
part):
if(kirby()->option('kirbytext.image.figure') or !empty($caption)) {
$image = $_link($_image($tag->attr('imgclass')));
$figure = new Brick('figure');
$figure->addClass($tag->attr('class'));
$figure->append($image);
if(!empty($caption)) {
$figure->append('<figcaption>' . html($caption) . '</figcaption>');
}
return $figure;
} else {
$class = trim($tag->attr('class') . ' ' . $tag->attr('imgclass'));
return $_link($_image($class));
}
Is there a way to just override this section, or do I need to duplicate the whole defintion for the image tag?
If someone can push me in the right direction, that would be great