I’m creating a custom kirbytag for the audio element; I’ve modified the code for the files kirbytag like so:
<?php
Kirby::plugin('minttoothpick/audio-kirbytag', [
'tags' => [
'audio' => [
'attr' => [
'class',
'controls',
'title'
],
'html' => function ($tag) {
if (!$file = $tag->file($tag->value)) {
return $tag->text;
}
$source = Html::tag('source', null, [
'src' => $file->url(),
'type' => $file->mime(),
]);
return Html::tag('audio', [$source, 'Your browser does not support the audio tag.'], [
'controls' => $tag->controls !== 'false',
'class' => $tag->class,
]);
}
]
]
]);
Everything seems to be working, except when I nest the <source> ($source) tag in the returned <audio> (Html::tag()) tag, it’s not self-closing… instead, it wraps the fallback text inside of the <source>:
<audio controls>
<source src="url/to/my.mp3" type="audio/mpeg">
Your browser does not support the audio tag.
</source>
</audio>
I see in the docs for Html::tag() that if parameter 2 is set to null it should generate a self-closing tag… anyone have some advice?