Using $kirby inside plugin SiteMethods

How can I use the $kirby object inside my plugin’s siteMethods? The following code gives me the error: “Too few arguments to function Kirby\Cms\Site::{closure}(), 0 passed and exactly 1 expected”. I’d like to access my config variables from inside the plugins site method.

#site/plugins/kirby-weather/index.php

Kirby::plugin('visualdialogue/weather', [

...
    'siteMethods' => [
        'getCurrentTemperature' => function($kirby) {
        
            $apiKey = $kirby->option('openweather.key');
            ...
        }
...

You can use the kirby() helper for that:

#site/plugins/kirby-weather/index.php

Kirby::plugin('visualdialogue/weather', [

...
    'siteMethods' => [
        'getCurrentTemperature' => function() {
        
            $apiKey = kirby()->option('openweather.key');
            ...
        }
...
1 Like