ExpressionEngine 2024 Quarter 1 Review Quarter 1 Review
Can we use ENV variables in templates to do conditionals?
Interested in learning more solutions or want to get to know other EE users? Read more about joining the slack here! Join Our Slack!
In order to add ENV variables to your templates you’ll first need to add them to your .env.php
file (this file should sit next to your system directory):
# .env.php
ENV=production
Once you’ve defined your variables you need to add them to ExpressionEngine’s config:
// config.php
$global = [];
// Add your variables here
$global['global:env'] = $_ENV['ENV'];
global $assign_to_config;
if (! isset($assign_to_config['global_vars'])) {
$assign_to_config['global_vars'] = [];
}
You should now be able to access your global variables in your templates:
{!-- Template --}
{global:env}
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.