<p>I would use plugin settings to store these kinds of values. Then in your plugin files (controller, services etc.) you could call up the settings and adjust your output as needed.</p>

<pre><code>craft()-&gt;plugins-&gt;getPlugin('myPlugin')-&gt;getSettings()
</code></pre>

<p>As for asset paths and your site path, you can keep all of those relative by using the URL helper functions like 
<code>{{ url('assets/build/css/main.css') }}</code> and <code>UrlHelper::getUrl('/')</code> depending on where you are working.</p>

<p>Here's a related post - <a href="https://craftcms.stackexchange.com/questions/418/how-do-i-reference-the-settings-of-my-plugin">How do I reference the settings of my plugin?</a></p>

CC BY-SA 3.0
2014-08-18T19:12:40.750Z
2014-08-18T19:12:40.750Z
2017-04-13T12:51:00.253Z
Adam McCombs
<p>You can add a <code>config.php</code> file in the root of your plugin's folder (<code>craft/plugins/pluginhandle/config.php</code>) that specifies the default values of your config items by returning an array of key value pairs for config settings and values.</p>

<p>If a user wants to change any of those settings, they can add a <code>pluginhandle.php</code> config file to <code>craft/config/pluginhandle.php</code> that returns an array with the overridden key value pairs.</p>

<p>From your plugin, if you call:</p>

<p><code>craft()-&gt;config-&gt;get('key', 'pluginhandle')</code></p>

<p>then Craft will return the user supplied value, if it exists, and fallback on the plugin supplied default value, if it does not.</p>

<p>Also worth nothing that all of Craft's <a href="http://buildwithcraft.com/docs/multi-environment-configs">multi-environment config stuff</a> will work in this context for the plugin, too.</p>

CC BY-SA 3.0
2014-08-18T19:29:01.247Z
That's really helpful to know!
Alec Ritson
CC BY-SA 3.0
2015-02-07T04:26:04.087Z
Is this in the docs?
Luke Holder
CC BY-SA 3.0
2016-06-27T09:02:38.367Z
Does multi-enviroment config really work in this context? Does not seem to be working for me. This answer also seems to imply it does not work: http://craftcms.stackexchange.com/questions/12778/plugin-multi-environment-config-not-working?lq=1
Kristian J.
CC BY-SA 3.0
2016-06-27T17:44:41.490Z
@KristianJ. It works in the sense you can override your default plugin values (that live in `plugins/pluginHandle/config.php`) in the multi-environment config part of `craft/config/pluginHandle.php`.
Brad Bell
CC BY-SA 3.0
2014-08-18T19:23:49.937Z
2014-08-18T19:29:49.553Z
2014-08-18T19:29:49.553Z
Brad Bell
<p>When building a plugin, how does one define user editable config files? Would it be better to create a settings UI in the plugin and have the user edit those variables in the CP? Or is there a way to do it properly with a config file? </p>

<p>The reason I want to opt for a config option is so the value can be localized for the specific environment to set different options. I need to add the ability to define a public directory that will be used to store generated images and obviously that path could be different on local and production environments.</p>

<plugin-development><custom-fieldtype>
How does a plugin include it's own config options?
# How does a plugin include it's own config options?

(Asked by: username_0 on 2014-08-18)

When building a plugin, how does one define user editable config files? Would it be better to create a settings UI in the plugin and have the user edit those variables in the CP? Or is there a way to do it properly with a config file?

The reason I want to opt for a config option is so the value can be localized for the specific environment to set different options. I need to add the ability to define a public directory that will be used to store generated images and obviously that path could be different on local and production environments.

**Tags:** plugin-development, custom-fieldtype


---

## 2 answers

### Answer by username_2 on 2014-08-18. Score: 11 | Accepted answer

You can add a `config.php` file in the root of your plugin's folder (`craft/plugins/pluginhandle/config.php`) that specifies the default values of your config items by returning an array of key value pairs for config settings and values.

If a user wants to change any of those settings, they can add a `pluginhandle.php` config file to `craft/config/pluginhandle.php` that returns an array with the overridden key value pairs.

From your plugin, if you call:

`craft()->config->get('key', 'pluginhandle')`

then Craft will return the user supplied value, if it exists, and fallback on the plugin supplied default value, if it does not.

Also worth nothing that all of Craft's [multi-environment config stuff](http://buildwithcraft.com/docs/multi-environment-configs) will work in this context for the plugin, too.

> **Comments:**
> **username_3**: That's really helpful to know!  
> **username_4**: Is this in the docs?  
> **username_5**: Does multi-enviroment config really work in this context? Does not seem to be working for me. This answer also seems to imply it does not work: http://craftcms.stackexchange.com/questions/12778/plugin-multi-environment-config-not-working?lq=1  
> **username_2**: @KristianJ. It works in the sense you can override your default plugin values (that live in `plugins/pluginHandle/config.php`) in the multi-environment config part of `craft/config/pluginHandle.php`.  

---

### Answer by username_1 on 2014-08-18. Score: 2

I would use plugin settings to store these kinds of values. Then in your plugin files (controller, services etc.) you could call up the settings and adjust your output as needed.
craft()->plugins->getPlugin('myPlugin')->getSettings()

As for asset paths and your site path, you can keep all of those relative by using the URL helper functions like 
{{ url('assets/build/css/main.css') }} and UrlHelper::getUrl('/') depending on where you are working.
Here's a related post - How do I reference the settings of my plugin?


---

