Use Dir/Root Constants in config.php ($kirby undefined in config.php)


I want to define a dir (for loading inline svg via svg()) helper in various tpls)

I thought off placing them in the config like so

return [
    'icon_dir' => $kirby->root('assets') . '/images/icons/'

and getting them with


but I get

**Notice** : Undefined variable: kirby

Any other ideas to set global dirs?


maybe define own roots in index.php? like described here: ?

The right way to call the Kirby instance outside of templates/controllers would via the kirby() helper. However, you can’t call kirby() in the config file unless you use it inside a closure.

Note that c::get() doesn’t work anymore, use the option() helper to fetch an option.

1 Like

thanks for clarifying, do you have a recommendation, how to store a path like this?

This should work:

return [
    'icon_dir' => function () {
        return kirby()->root('assets') . '/images/icons/';

In template:

<?= option('icon_dir')() ?>
1 Like

thank you