We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Can we use ENV variables in templates to do conditionals?

How Do I?

From EE Slack's avatar
From EE Slack
185 posts
one year ago
From EE Slack's avatar From EE Slack

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!

       
Jared Chesebro's avatar
Jared Chesebro
15 posts
one year ago
Jared Chesebro's avatar Jared Chesebro

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}
       
Laverneleg's avatar
Laverneleg
1 posts
one year ago
Laverneleg's avatar Laverneleg

Great sharing, amazing, thank you so much.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.