Skip to content

Kirby 3.5.7.1

Options

Registering options

Options are registered with the options extension. The extension accepts an array of options with their default values. The default values will be used if the options are not overwritten in the site config.

Kirby::plugin('yourname/yourplugin', [
    'options' => [
        'option' => 'some-value',
        'another-option' => [
            'with-a-nested-option' => 'and values'
        ]
    ]
]);

Setting custom options in the site config

Your custom options can be set like core Kirby options in the site/config/config.php:

/site/config/config.php
<?php

return [
    'yourname.yourplugin' => [
        'option' => 'a custom value',
        'another-option' => [
            'with-a-nested-option' => 'also a custom value'
        ]
    ]
];

Before Kirby 3.4.0, only the following syntax was supported:

/site/config/config.php
<?php

return [
    'yourname.yourplugin.option' => 'a custom value',
    'yourname.yourplugin.another-option' => [
        'with-a-nested-option' => 'also a custom value'
    ]
];

This syntax is now deprecated because it turned out to be confusing. For now, the old syntax is still supported to ensure backwards-compatibility.

Accessing option values

Config options can be used anywhere in Kirby with the $kirby->option() method:

$kirby->option('yourname.yourplugin.option');
$kirby->option('yourname.yourplugin.another-option.with-a-nested-option');

Or with the option() helper:

option('yourname.yourplugin.option');
option('yourname.yourplugin.another-option.with-a-nested-option');