Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-03T12:29:29.843Z
Answers.LastActivityDate: 2022-06-22T07:51:28.803Z
Answers.LastEditDate: 2022-06-22T07:51:28.803Z
Answers.UserDisplayName: MoritzLost
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-03T12:40:18.230Z
Answers.LastActivityDate: 2022-06-03T12:40:18.230Z
Answers.UserDisplayName: James White
Body: <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>
  
Tags: <environmentvariables><craft4>
Title: Craft 4 Custom Variables - From Env > General.php > template
ThreadText: # 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`:
  
  ```twig
  {{ craft.app.config.custom.variablestored }}
  
  ```
  
  This is covered in the [upgrade guide for Craft 4](https://craftcms.com/docs/4.x/upgrade.html#configuration).
  
  **Update 2022-06-22:** The [documentation on configuration settings](https://craftcms.com/docs/4.x/config/) now mentions [custom settings](https://craftcms.com/docs/4.x/config/#custom-config-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 @username_1, 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').
  
  
  ---
  
  