11 votes
Accepted

Getting environmental variable via plugin

Solution: return craft()->config->get('environmentVariables')['baseUrl'];
user avatar
  • 2,265
9 votes
Accepted

How to set up multi-env in Craft 3 with .env files?

These are the two approaches I usually choose from: Option 1: the 'default' Craft 3 way Create a .env file for every environment you create, and add it to your .gitignore file (if it's not yet in it)...
user avatar
  • 6,288
6 votes
Accepted

devMode, phpdotenv variable ignored

It looks like getenv returns a string (or false if the variable is not set, but it is in this case). So you need to cast the string to a boolean value to make it work. However, (bool)'false' gives ...
user avatar
  • 35.9k
5 votes
Accepted

Asset Volume using Environment Variable on File System Path as literal string on upload

If you use environment variables, you have to be aware that you can't add anything to it in your fields. What this means is that $ASSET_ADHOC_PATH/website in your CP will not be parsed. If you use ...
user avatar
  • 7,200
5 votes
Accepted

Using Craft environment variable for Asset source subfolder

From the docs, environment variables are currently only parsed in 3 places in the control panel. File System Path (in asset source settings) URL (in asset source settings) Site URL (in Settings → ...
user avatar
  • 66.5k
4 votes
Accepted

How can I parse environment variables in a string?

craft()->config->parseEnvironmentString($string)
user avatar
  • 7,248
4 votes

Just upgraded to Craft 3, environmentVariables changed or stopped working

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 ...
user avatar
3 votes

How can I access environment variables from a javascript file in Craft 3?

The .env file is on the server and javascript is running in the client so you need to pass it through to javascript in your twig template inside a script tag. {% set env = getenv('ENVIRONMENT') %} &...
user avatar
  • 166
3 votes
Accepted

Craft 3: Environment variables are not parsed when used in Assets source field

Environmental variables as such don't exist "as a thing" in Craft 3. Instead, you'd define your Volumes in the AdminCP and override anything you need in craft/config/volumes.php You can see an ...
user avatar
3 votes
Accepted

Custom Environmental Settings

Yes it's absolutely possible, and available out of the box with craft. In your public/index.php file you specify the different environments based on your server name. With the environment set, ...
user avatar
  • 231
3 votes

How to parse environment variables and globals from a field

You can use my Filter Environment Variables plugin, which will get you about half-way there. It will automatically parse out any environment variables which show up in your dynamic fields... {{ entry....
user avatar
  • 23.6k
3 votes
Accepted

How to set SMTP Enrcyption with an environment variable

You can name the environment variable whatever you want. The trick is that the variable's value needs to be either none, ssl or tls (i.e. the three options that are supported for the "Encryption ...
user avatar
3 votes
Accepted

Craft 4 Custom Variables - From Env > General.php > template

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....
user avatar
  • 6,820
2 votes

How to parse environment variables and globals from a field

You could enable your client to use Reference Tags by adding the parseRefs filter. {% set str = '<p>Since {globalset:42:yearEstablished}</p>' %} {{ str|parseRefs|raw }} But this would ...
user avatar
  • 35.9k
2 votes
Accepted

Using a dynamic url with Feed Me

There's currently no method to parse variables into the feed itself through this, or any means. Typically, we approach this as feeds being third-party, or otherwise non-editable. How would you see ...
user avatar
  • 3,402
2 votes
Accepted

Environmental variable coming back as literal braces

Your config/general.php file code has some problem with it. You're missing a closing ) for an array, which I suspect is a typo, but the issue to your real problem is probably the fact you're missing ...
user avatar
  • 66.5k
2 votes

Images are broken when I upload them

It was a simple misunderstanding of how the general.php should be structured. I had environmentVariables outside of the '*' => array( So it's now: return array( '*' => array( '...
user avatar
  • 171
2 votes
Accepted

baseUrl outputs environment variable

You can get it to return the url using the siteUrl function and passing it a siteId parameter. So do: {% set sites = craft.app.sites.getAllSites() | without(currentSite) %} {% for site in sites %} ...
user avatar
  • 7,200
2 votes
Accepted

Managing `isSystemLive` with Project Config

You can use the console commands off and on to take the system offline or online, respectively. This bypasses the allowAdminChanges setting and is explicitly intended for usage during deployments. In ...
user avatar
  • 6,820
2 votes
Accepted

Are there any benefits to using Yii's Aliases vs getenv?

Performance? Doubtful there is a significant difference, compared to the cost of, say, a database query. It all boils down to accessing arrays, and the number of function calls or string manipulations ...
user avatar
2 votes

Craft 4 Custom Variables - From Env > General.php > template

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 ...
user avatar
  • 1,031
1 vote

All Plugins Showing "Not Installed" After Promoting Changes From Dev to Stage Environments

"After pushing the exec widget all the codebase changes, fields, sections are moved to the Staging environment." You skipped a step... Assuming you are properly using Project Config, you'll ...
user avatar
  • 23.6k
1 vote

Template URL/path alias

For the entry URI format, you can use Twig, so you can include environment variables in the URL of an entry: {{ getenv('CURRENT_THEME') }}/{slug} However, the entry URI is parsed when the entry is ...
user avatar
  • 6,820
1 vote

Craft Script: Environment variable GLOBAL_DB_DRIVER was neither 'mysql' nor 'pgsql'

The error you're seeing is probably caused by this: ./.env.sh: line 128: $'\r': command not found This error indicates that your OS doesn't recognise the line endings in this file. This means the file ...
user avatar
  • 6,820
1 vote
Accepted

Configure path craft uses for composer and php

As I looked at it more and how php does environment variables; I discovered the thing that was different was the system $PATH variable. In bash on linux; this is what sets the search order for trying ...
user avatar
  • 131
1 vote

Use .env values in Craft 3 plugin settings

You could try declaring the variable $youtubeApiKey with no value set. Instead of using public $youtubeApiKey = '$YOUTUBE_API_KEY'; try using public $youtubeApiKey;
user avatar
1 vote
Accepted

Error using environment variable for email setting

I think you're getting a few conventions mixed up. Using an @ is typically reserved for aliases https://docs.craftcms.com/v3/config/environments.html#using-aliases-in-control-panel-settings What you'...
user avatar
  • 66.5k
1 vote
Accepted

ImageOptimize not using image url specified in my multi-environment setup and my volume config

You need to re-index your assets to show the correct URL after changes to your volume location when using imageOptimize. Just re-save the volume from within Craft CMS. Even if you have made amends to ...
user avatar
  • 1,107
1 vote
Accepted

Can I get the value of an environment variable in routes.php (or other config files)?

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'], );
user avatar
  • 66.5k
1 vote

Include Global Set Variable in Print Delimiters

You'd want to do something like this: {{ "#" ~ craft.config.siteCode ~"Defaults.defaultTelephoneLink" }}
user avatar
  • 66.5k

Only top scored, non community-wiki answers of a minimum length are eligible