Kirby Shortcode

It was a long time ago since I released a new plugin, but today is the day.

Download: https://github.com/jenstornell/kirby-shortcode

Kirbytags alternative

Kirby Shortcode is a powerful alternative to kirbytags, but it’s more similar to WordPress Shortcode API.

Kirbytags Shortcode
Self closing Yes Yes
Closing - Yes
Nesting - Yes
Any HTML - Yes
Access to $field Yes Yes
Access to $page Yes Yes

Kirbytags, markdown and HTML still works like before, even inside shortcodes.

Example content text

[hello]

Some text.

[greetings firstname="Peter" lastname="Parker"]
    [hello] This is a tag inside a tag.
    Kirby *markdown* can be used inside a tag.
    Html can be <strong>used as well</strong>!
    Even kirbytags like (email: hello@example.com) works.
[/greetings]

Some more text.

[field-data]

Syntax

c::set('plugin.shortcode.create', [
    [
        'name' => 'hello',
        'text' => function() {
            return 'Hello world!';
        }
    ],
    [
        'name' => 'greetings',
        'text' => function($shortcode) {
            return sprintf(
                '**Greetings** %s %s!<br>%s',
                $shortcode->getParameter('firstname'),
                $shortcode->getParameter('lastname'),
                $shortcode->getContent()
            );
        }
    ],
    [
        'name' => 'field-data',
        'text' => function($shortcode, $field) {
            return sprintf(
                '**Field key:** %s
                **Page title:** %s',
                $field->key,
                $field->page->title()
            );
        }
    ]
]);

For more details, more on Github.

1 Like