<p>You're still trying to access the custom config settings through the general config, this is what's causing the error. Instead of <code>craft.app.config.general</code>, use <code>craft.app.config.custom</code>:</p>
<pre class="lang-twig prettyprint-override"><code>{{ craft.app.config.custom.variablestored }}
</code></pre>
<p>This is covered in the <a href="https://craftcms.com/docs/4.x/upgrade.html#configuration" rel="nofollow noreferrer">upgrade guide for Craft 4</a>.</p>
<p><strong>Update 2022-06-22:</strong> The <a href="https://craftcms.com/docs/4.x/config/" rel="nofollow noreferrer">documentation on configuration settings</a> now mentions <a href="https://craftcms.com/docs/4.x/config/#custom-config-settings" rel="nofollow noreferrer">custom settings</a> explicitly, including code examples for accessing custom config values in both Twig and PHP.</p>

CC BY-SA 4.0
2022-06-03T12:29:29.843Z
2022-06-22T07:51:28.803Z
2022-06-22T07:51:28.803Z
MoritzLost
<p>As highlighted by @MoritzLost, in Twig, you should be calling <code>{{ craft.app.config.custom.myVar }}</code>, not using the GeneralConfig service.</p>
<p>Also worth highlighting, rather than calling getenv() in your custom.php, you can use the App helper, with App::env('testtest').</p>

CC BY-SA 4.0
2022-06-03T12:40:18.230Z
2022-06-03T12:40:18.230Z
James White
<p>Been trying for a wee while, but no joy so far. This worked in Craft 3, but not in Craft 4.</p>
<p>It's a CSS cache buster, I basically want a variable to set in env, then taken into general.php[caveat] and then onto a template.</p>
<p>It seems you cannot have custom variables in Craft 4 in config/general.php. I've created a config/custom.php</p>
<p>// env</p>
<pre><code>testtest=123456
</code></pre>
<p>// config/custom.php</p>
<pre><code>'variablestored' =&gt; getenv('testtest'),
</code></pre>
<p>//template</p>
<pre><code>{{ craft.app.config.general.variableStored }}
</code></pre>
<p>Results in an error: Calling unknown method: craft\config\GeneralConfig::variableStored()</p>
<p>Many thanks.</p>

<environmentvariables><craft4>
Craft 4 Custom Variables - From Env > General.php > template
# Craft 4 Custom Variables - From Env > General.php > template

(Asked by: username_0 on 2022-06-03)

Been trying for a wee while, but no joy so far. This worked in Craft 3, but not in Craft 4.
It's a CSS cache buster, I basically want a variable to set in env, then taken into general.php[caveat] and then onto a template.
It seems you cannot have custom variables in Craft 4 in config/general.php. I've created a config/custom.php
// env
testtest=123456

// config/custom.php
'variablestored' => getenv('testtest'),

//template
{{ craft.app.config.general.variableStored }}

Results in an error: Calling unknown method: craft\config\GeneralConfig::variableStored()
Many thanks.

**Tags:** environmentvariables, craft4

---

## 2 answers

### Answer by username_1 on 2022-06-03. Score: 3 | Accepted answer

You're still trying to access the custom config settings through the general config, this is what's causing the error. Instead of craft.app.config.general, use craft.app.config.custom:
{{ craft.app.config.custom.variablestored }}

This is covered in the upgrade guide for Craft 4.
Update 2022-06-22: The documentation on configuration settings now mentions custom settings explicitly, including code examples for accessing custom config values in both Twig and PHP.


---

### Answer by username_2 on 2022-06-03. Score: 3

As highlighted by @MoritzLost, in Twig, you should be calling `{{ craft.app.config.custom.myVar }}`, not using the GeneralConfig service.

Also worth highlighting, rather than calling getenv() in your custom.php, you can use the App helper, with App::env('testtest').


---

