Hello everyone!
I have a small issue with custom tags. I created a custom tag as following:
a simple svg tag that renders a svg not as <img>
but <svg>
index.php
snippets/svg-tag.php
in the panel:
In general it works with no problems. it recognizes the file and renders this:
My only issue is: Why is it rendering the svg tag first, and then the text? Which is the wrong order. In the Panel i added Text first, then the svg.
What am i doing wrong here?
Thanks in advance!
Jasmin
Please post your code as code so that I can reproduce without having to type out everything, thanks.
my bad. not so experienced with writing in forums
index.php
<?php
Kirby::plugin('myplugin/svg-tag', [
'snippets' => [
'svg-tag' => __DIR__ . '/snippets/svg-tag.php'
],
'tags' => [
'svg' => [
'attr' => [
'caption'
],
'html' => function($tag) {
$svg = $tag->parent()->file($tag->value);
$caption = $tag->caption;
return snippet('svg-tag', ['svg' => $svg, 'caption' => $caption]);
}
]
]
]);
snippets/svg-tag.php
<figure>
<?= svg($svg) ?>
<figcaption>
<?= $caption ?>
</figcaption>
</figure>
You need to pass true
as third parameter to just return instead of echo the snippet:
return snippet('svg-tag', ['svg' => $svg, 'caption' => $caption], true);
ahhh great! so simple. thanks a bunch @texnixe