Adding snippet with markdown


on some pages we want to add a newsletter subscription form as a snippet in the panel as markdown. I’m pretty sure, that this was possible in the past with
(snippet: nl-subscription)
but now only “(snippet: nl-subscription)” is shown instead of the form in the snippet. Has something changed, so this is not possible anymore, if so, is there an alternative way to add snippets with markdown?

Does the kirbytag snippet exist?
In what sort of field are you using this Kirbytag?
How are you rendering the field in the frontend?
What is your current Kirby version?

Yes the snippet does exist and has only an opening div-tag and no closing one.
The field is a textarea.
In the frontend we incude the text with: <?= $page->text()->kirbytext() ?>
I’m testing this in a demo version of Kirby 3.9.2

That doesn’t sound right.

Strange, I even took a note that it is important, not to close the div when using the snippet in markdown-text… However, it doesn’t make a difference if I close the tag in the snippet.

Just to make sure this is clear: in standard Kirby there is no (snippet: …) kirbytag.
If in the past you have used this, you must have had a plugin that added that tag.

You mentioned that you are “testing this in a demo version of Kirby”, have you correctly installed that plugin and is that plugin compatible with Kirby 3.9.2?

Texnixe asked if “the kirbytag exists” and you answered that “the snippet exists”, this just looks like a misunderstanding to me :wink:

Oh, yes you are right, Texnixe was asking for the kirbytag and I was referring to the snippet.

Actually I had this running some time ago and now I saw, that it is not working anymore. I don’t remember if I have installed a plugin for this and if I’m searching for it I don’t find something suitable.

Is there recommended way to include snippets in kirbytext?

An alternative to the kirbytag could be a string template that you replace when rendering in the the template:

Some text {{ mynewslettersnippet }}

In template

<?= Str::template($page->text()->kt(), [
    'mynewslettersnippet' => snippet('mynewslettersnippet', [], true),
]) ?>

But with a kirbytag, it’s more comfortable of course, because that will be rendered automatically when you call kirbytext().

The plugin could be as simple as:



use Kirby\Cms\App as Kirby;

Kirby::plugin('hennerb/snippettag', [
    'tags' => [
        'snippet' => [
            'html' => fn($tag) => snippet($tag->value, [], true)

This is untested, but I think it should work

Great, the plugin code is working :slight_smile:

Thank you both @rasteiner and @texnixe!