Embedding Snippets

Yes. Imageshrink and Focus

Does it make any difference if you remove those plugins? Can’t see how those would interfere, though.

Edit: I just saw something else: the original snippet you posted, is not wrapped in a container, but should be. Could you try that, please?

Good eye. I wrapped my snippet code in a DIV and it worked. I wouldn’t have thought of that. I’ll have to chalk that up as a rule to remember.

Thanks for your help!!!

FYI: The HTML in a Kirbytag definition has to be wrapped in a container as well.

Does this snippet tag need to be revised to work in Kirby v3?

The snippet itself: no; the way you create your custom kirbytag: yes.

/site/plugins/custom-tags/index.php

<?php
Kirby::plugin('yourname/custom-tags', [

    'tags' => [
        'snippet' => [
            'html' => function($tag) {
                return snippet('snippetname');
            }
        ]
    ]
]);

Or with dynamic snippet names

<?php
Kirby::plugin('yourname/custom-tags', [

    'tags' => [
        'snippet' => [
            'html' => function($tag) {
                $snippetName = $tag->value();
                return snippet($snippetName);
            }
        ]
    ]
]);
1 Like

@texnixe Is there something further that one needs to do to make the V3 plug-in above (dynamic snipped names) besides install it to the plug-in folder? Despite installation (plugins>custom-tags>custom-tags.php), my snippet tags are not replaced.

Example:

Version: (snippet: version-snippet)

… where version-snippet.php is in the snippets folder.

Even after installing the plug-in, this is rendered on the live HTML page as:

Version: (snippet: version-snippet)

There was a typo, now corrected, if you just copied it as is, maybe that is the issue.

Got it. I fixed the typo, but same results on the issue I’m seeing.

Even if I simply:

return "hello";

… “(snippet: version-snippet)” still appears in my rendered text. It’s as if the plug-in isn’t recognized at all.

Sorry, I’m a dummy. I was naming the plugin “custom-tags.php” instead of “index.php”. All fixed. Thanks. :slight_smile:

Actually, I now have a follow-up issue. The snippet text always renders at the top of my page.

This is my Markdown file:

Text:
test1
(snippet: version-snippet)
test2

Yet, when visiting the rendered page, it appears as:

1.0
test1

test2

(“1.0” is the content of the snippet)

Any idea on why it’d always render at the top of the page vs. inline where it’s supposed to go?

 return snippet($snippetName, [], true);
1 Like

Thank you for this great help! I would like to reopen this post: everything is working so far, but I still have the problem, that the snippet is rendered at the top. When using your last code the bare code is rendered in the frontend. Could you assist here again, please? My current file looks like this:

<?php
Kirby::plugin('yourname/custom-tags', [

    'tags' => [
        'snippet' => [
            'html' => function($tag) {
                $lightboxgallery = $tag->value();
                return snippet($lightboxgallery, [], false);
            }
        ]
    ]
]);

Just solved it and wanted to post, if anybody else has this problem! It´s not a matter of code, it´s because of the empty lines in the snippet. Sounds strange? But it´s true: just remove the empty lines and it works! It seems that code formatting is an important thing here. Thank you anyhow for this great support!

1 Like

Yes, that’s a problem with the Parsedown library. There is already an issue to replace it one day, but…

2 Likes

I was searching for this, but I didn’t know where to look for embedded snippets in text.
Also the information I found in the docs was a bit fragmented. I found the following:

In Kirby it’s called KirbyTags.

You can use tags in your texts (edited via the panel). But these text(fields) must have an extra function so the kirbyTag gets rendered: ->kirbytext().
e.g:
<p><?= $block->alinea()->kirbytext() ?></p>
where alinea() is my fieldname that needs to be rendered.

There are default KirbyTags like (date: year) and you can create your own tag.