Is it possible to set Configuration values via a Plugin?

Hey there,

Is it possible to set Configuration values via a Plugin?

greetings

Yes, but only if not already set in the config like so:

kirby()->extend([
    'options' => ['debug' => true]
]);

I.e the same option in config.php overwrites the options set in your plugin.

Ah, so like usual with snippets and templates aswell

Many Thanks

Is there also a way to tell kirby to use different configurations depending on the domain in this context?
Lately i had a “config.localhost.php”

You could wrap this extension into an if statement depending on host.

Or

kirby()->extend([
    'options' => require __DIR__ . '/config.' . Url::host() . 'php',
]);

Then in your plugins config.localhost.php etc:

<?php

return [
  'debug' => true,
  // etc.
];

Ah, this makes sence thanks!
If it looks for “/config.domainxy.php” and doesnt find it, will it search for “/config.php” automatically?

The idea is to have a “config.localhost.php” with debug mode on and some stuff and a “config.php” with the productionvalues for the customer

Nope. You would have to implement some logic for that

Alright. Just for the context here, this is how i solve it:

$configPath = '/config/config.' . Url::host() . '.php';

if(!file_exists($configPath)) {
  $configPath = '/config/config.php';
}

kirby()->extend([
  'options' => require __DIR__ . $configPath,
]);

Good night and thanks again!

2 Likes