Kirby

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

Hi,

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

c::get('icon_dir')

but I get

**Notice** : Undefined variable: kirby

Any other ideas to set global dirs?

thanks!

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

https://getkirby.com/docs/reference/system/roots/site ?

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.

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')() ?>

thank you