10

Solution: return craft()->config->get('environmentVariables')['baseUrl'];


8

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). In this file, you put all environment-specific details; Craft, by default, will recognize and use those details. In your Craft config files, you can use the ...


5

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 true, not false. There are two possible solutions: Set the variable to 0 instead of false in your .env file: DEV_MODE=0 AUTO_UPDATE=0 And then in your config: '...


4

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.


4

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 environment variables, the only thing you should have in the field is the variable, nothing else. To do what you are trying to do, you might want to consider ...


4

craft()->config->parseEnvironmentString($string)


4

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 → General) So they won't work in the "subfolder" setting. You can add a feature request if you think that should change.


3

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 example of how to do it here: Craft 3 Multi-Environment


3

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, inside your craft/config/db.php and craft/config/general.php files, you can create different configurations for each environment. This article in the craft ...


2

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.myField | envvar }} Once you've got that installed, it's fairly easy to adjust the logic to accommodate for globals as well. Go to /filterenvvar/...


2

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 enable them to access field values of (almost) any element (entries, assets, tags, ..), not just from global sets. And they would also have to remember the global ...


2

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 utilising issueNumber to work in this scenario? You can use the concept of aliases in your URL if that helps? Lastly, you could also make use of the (...


2

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 the required '*' key for multi-environment configs to work properly. See the first warning note on this page: https://craftcms.com/docs/multi-environment-...


2

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( 'omitScriptNameInUrls' => true, 'sendPoweredByHeader' => false, 'devMode' => getenv("CRAFT_DEVMODE") == "true", 'environmentVariables' => array( ...


2

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 %} <li><a href="{{ siteUrl(siteId=site.id) }}" title="{{ site.language }}">{{ site.language }}</a></li> {% endfor %} I don't know if it's ...


2

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') %} <script> var myVariable = '{{ env|e('js') }}' </script> You probably don't need to escape it like in my example above, but good practice anyway. ...


2

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 that it takes to get there is probably not worth worrying about. The way I see it is that ENV vars are for configuration, and aliases are for convenience / ...


1

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're probably looking for is environment variables in your .env file. You could set: EMAIL_HOST=myhost EMAIL_PORT=myport EMAIL_USERNAME=myusername ...


1

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 your volume config file you will need to re-save from within Craft CMS. To quote Andrew, the plugin author... "So I want to say that this is normal (though ...


1

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'], );


1

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


1

Check out craft-multi-environment; even if you don't use it, you might crib some of the ideas from it. For instance, how the basePath is determined.


1

The easiest option is probably to use inline styles in your markup for the relevant element(s): {% set sitePath = craft.config.environmentVariables.sitePath %} <div class="foo" style="background-image:url('{{ sitePath }}/assets/bg.jpg');"> <img src="{{ sitePath }}/assets/logo.png" alt="" /> </div>


1

With Craft 3 and/or Twig, there is a nice easy way to manage this now. To output environment variables, config variables, globals, etc you can use {{ view.renderString(entry.richText) }}, the renderString method will parse a template as a string. There is also Twig's template_from_string() which allows you to parse any text as a Twig template, with access to ...


1

"Upload Location" doesn't reference you're environment variables. Instead, you've got a dropdown menu of your pre-defined Assets sources. Whichever one you choose will be used as the base of your file path. Anything you put in curly braces after that will become a subfolder of that asset source. So your subfolder names will be created based on whichever ...


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