1

I'm currently working on migrating a Craft 2 project which has a bunch of bespoke custom plugins that provided various bits of additional functionality that's tailored to this project only. I've been reading up on the recommended approach in Craft 3 and have understood that modules are better suited in a lot of cases.

However, I've come across a snag with a previous Craft 2 plugin, that basically existed to provide settings that could be referenced in PHP/Twig. This plugin implemented various settings that were defined at config/mycustompluginhandle.php.

I'd like to have the same again but as a module, but it looks like the settings model isn't the same as a plugin and you have to "roll your own" setup for this.

My question is can is a module provide settings via a config/something.php file and can these settings be referenced in other parts of the application i.e. PHP/Twig or another plugin/module? If so, how can I go about doing achieving it?

1

So based on a bit of research. I don't think you necessarily have to create a settings model, if the settings are purely required from a config file. You could use something like:

$settings = Craft::$app->config->getConfigFromFile('configfilename');
$exampleSettings = $settings['exampleSomething'];

$settings would be an array, which you could then access each array key.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.