<p>I think you'll just need to do something like this in your <code>routes.php</code> file:</p>

<pre><code>$general = require __DIR__.'/general.php';

return array(
    'foo' =&gt; $general['environmentVariables']['bar'],
);
</code></pre>

CC BY-SA 3.0
2017-08-09T22:25:45.803Z
2017-08-09T22:25:45.803Z
Brad Bell
<p>I am trying to get the value of an environment variable (defined in the general.php config file) in the routes.php config file. Is it possible or not? I tried <code>$environmentVariables = craft()-&gt;config-&gt;get('environmentVariables')['myVariable']</code> but that throws an error: <code>Call to undefined function craft()</code>.</p>

<config><multi-environment><environmentvariables>
Can I get the value of an environment variable in routes.php (or other config files)?
# Can I get the value of an environment variable in routes.php (or other config files)?

(Asked by: username_0 on 2017-08-09)

I am trying to get the value of an environment variable (defined in the general.php config file) in the routes.php config file. Is it possible or not? I tried `$environmentVariables = craft()->config->get('environmentVariables')['myVariable']` but that throws an error: `Call to undefined function craft()`.

**Tags:** config, multi-environment, environmentvariables


---

## 1 answers

### Answer by username_1 on 2017-08-09. Score: 1 | Accepted answer

I think you'll just need to do something like this in your routes.php file:
$general = require __DIR__.'/general.php';

return array(
    'foo' => $general['environmentVariables']['bar'],
);


---

