In my Craft 2 install, I had many links in Twig templates like this:

<link rel="stylesheet" href="{{ craft.config.environmentVariables.baseUrl }}assets/css/styles.css">

I recently upgraded to Craft 3, and on my local environment, these links no longer work. I get this error:

Neither the property "environmentVariables" nor one of the methods "environmentVariables()", "getenvironmentVariables()"/"isenvironmentVariables()"/"hasenvironmentVariables()" or "__call()" exist and have public access in class "craft\web\twig\variables\Config".

Is there a new way of using environment variables (or whatever they are now called) in Craft 3? I'm just trying to set links to the site URL, but I'd like to have that be different for my local development site and the production site. I found some documentation on how to use environment variables in Control Panel settings, but nothing about Twig templates.

1 Answer 1


Environment variables don't exist in Craft 3 in the same way that they existed in Craft 2. Instead, they have been replaced with system environment variables and aliases.

The Changes in Craft 3 docs explain what changes have been made and the Environmental Configuration explains how you can set these up and use them.

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.