Using site variables in text snippets


I have created a Kirbytext filter for an email address. It works fine if I add the email address in the config file, but I would like to use the value from the site settings instead.

This works:

c::set('kirbytext.snippets', array(
    'email' => '',

This doesn’t:

c::set('kirbytext.snippets', array(
    'email' => $site->email(),

It gives me a blank screen, indicating a PHP error.

I have tried replacing the email value in the plugin file like this:

kirbytext::$pre[] = function($kirbytext, $value) {
    $snippets = c::get('kirbytext.snippets', array());
    $values   = array_values($snippets);
    $keys = array_map(function($key) {
        $key = $site()->phone()->email();
        return '{{' . $key . '}}';
    }, array_keys($snippets));
    return str_replace($keys, $values, $value);

But that gives an error too.

Any ideas what I am doing wrong?
Thanks in advance.

1 Like

Try: kirby()->site()->email()

Thank you very much. That’s working fine.


i have the same setup exept i’m using it on a multilang website.
I get the data with kirby()->site()->url() but i got an error :

Notice:  Trying to get property of non-object in /kirby/branches/multilang/page.php on line 199
Notice:  Trying to get property of non-object in /kirby/branches/multilang/page.php on line 202 

any idea?

Same error-message in this thread - Sitemap.xml returns error, due to language config

Maybe it has something to do with the missing setting for the active language (like in that thread).