Skip to content

Commit 6a204a3

Browse files
authored
Merge pull request #781 from ExpressionEngine/feature/7.x/global-vars-in-config
Document setting global variables in config file
2 parents f8a5ce1 + ac6b89f commit 6a204a3

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

docs/general/system-configuration-overrides.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ WARN: **Warning:** This article covers advanced topics.
1919

2020
By default, ExpressionEngine's system settings are managed in the Control Panel and stored in the database, but these settings can be overridden with one of 3 configuration files: the main configuration file, the site index file, and the CP index file.
2121

22+
You can also [set your own global variables](templates/globals/single-variables.md#custom-global-variables) in the above mentioned files.
23+
2224
##### Main configuration file
2325

2426
The **main configuration file**, found at `system/user/config/config.php`, is loaded every time the system is run, meaning that config overrides set in `config.php` always affect the system's configuration.

docs/templates/globals/single-variables.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,32 @@ NOTE: **Note:** Like the `{current_time}` variable, `{variable_time}` is availab
255255

256256
The email address for the site, as specified in [Email Configuration](control-panel/settings/email.md).
257257

258+
## Custom Global Variables
259+
260+
You can define your own global variables as overrides in your `config.php` file or `index.php` file using `global_vars` property (which itself needs to be an associative array). These variables will be available to all of your templates.
261+
262+
NOTE: Do not confuse these with [Site Template Variables](templates/variable.md), which are defined in the control panel.
263+
264+
When using `index.php` file, you need set `global_vars` property in `$assign_to_config` array. For example:
265+
266+
$assign_to_config['global_vars'] = array(
267+
'show_banner' => 'y',
268+
);
269+
270+
When using `config.php` file, you need to set the `$config` array variable. For example:
271+
272+
$config['global_vars'] = array(
273+
'show_banner' => 'n',
274+
);
275+
276+
You can use the [environment variables](advanced-usage/env-support.md) for the values of global variables. For example:
277+
278+
$config['global_vars'] = array(
279+
'show_banner' => $_ENV['SHOW_BANNER'],
280+
);
281+
282+
Note that the global variables defined in `config.php` file will be overridden by the global variables defined in `index.php` file when a name conflict occurs.
283+
258284
## Member Variables
259285

260286
[TOC=3]

0 commit comments

Comments
 (0)