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


// config/custom.php

'variablestored' => getenv('testtest'),


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

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

Many thanks.

2 Answers 2


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.


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').

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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