Snippet in Kirbytext tag moves to top of Kirbytext?

I’ve got a Kirbytag that overrides the default file tag with my own version. This tag calls a snippet that I’ve built.

However, I’ve noticed that when this tag uses the snippet, the snippet itself is placed at the very beginning of the Kirbytext DOM rather than where it belongs in the output.

For example, if my Kirbytext is thusly:


(file: filename.pdf)


The actual output would be something like this:


This only happens when the tag uses a snippet. If I copy the code from my snippet and use it as the return string in site/tags/file.php, it is properly located in the output.

Am I doing something wrong? Is this a bug?

For the sake of completeness, here’s my code:



kirbytext::$tags['file'] = array(
	'attr' => array(
	'html' => function($tag) {

		$file = $tag->file($tag->attr('file'));
		$title = $tag->attr('title', $file->filename());

		return snippet('file', array(
			'file' => $file,
			'title' => $title


<div class="c-file-download">
<?php if(isset($title)): ?>
	<h3><?= $title ?></h3>
<?php endif ?>

	<svg xmlns="" width="171" height="193" viewBox="0 0 171 193" xmlns:xlink="">
			<path id="a" d="M1 0h126l45 45v148H1z"/>
			<mask id="b" width="171" height="193" x="0" y="0" fill="#fff">
				<use xlink:href="#a"/>
		<g fill="none" fill-rule="evenodd" transform="translate(-1)">
			<use stroke="#979797" stroke-width="8" mask="url(#b)" xlink:href="#a"/>
			<path fill="#979797" d="M125 47V3l44 44"/>
			<text fill="#979797" font-size="50" font-weight="700">
				<tspan x="50%" y="110" text-anchor="middle" style="text-transform: uppercase"><?= $file->extension() ?></tspan>
			<path fill="#979797" d="M1 143h171v50H1z"/>
			<text fill="#FFF" font-size="22" font-weight="700" transform="translate(1 143)">
				<tspan x="50%" y="33" text-anchor="middle"><?= $file->niceSize() ?></tspan>

	<a class="o-button" href="<?= $file->url() ?>">Download</a>

Set the third parameter to true:

return snippet('file', array(
			'file' => $file,
			'title' => $title
		), true);
1 Like

Thanks @texnixe, that fixed it!