Skip to content

Commit 24e09ae

Browse files
committed
Document setting global variables in config file
1 parent b8b7005 commit 24e09ae

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 those 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
@@ -251,6 +251,32 @@ NOTE: **Note:** Like the `{current_time}` variable, `{variable_time}` is availab
251251

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

254+
## Custom Global Variables
255+
256+
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.
257+
258+
NOTE: Do not confuse these with [Site Template Variables](templates/variable.md), which are defined in the control panel.
259+
260+
When using `index.php` file, you need set `global_vars` property in `$assign_to_config` array. For example:
261+
262+
$assign_to_config['global_vars'] = array(
263+
'show_banner' => 'y',
264+
);
265+
266+
When using `config.php` file, you need to set the `$config` array variable. For example:
267+
268+
$config['global_vars'] = array(
269+
'show_banner' => 'n',
270+
);
271+
272+
You can use the [environment variables](advanced-usage/env-support.md) for the values of global variables. For example:
273+
274+
$config['global_vars'] = array(
275+
'show_banner' => $_ENV['SHOW_BANNER'],
276+
);
277+
278+
Note that the global variables defined in `config.php` file will be overridden by the global variables defined in `index.php` file when the name conflict occurs.
279+
254280
## Member Variables
255281

256282
[TOC=3]

0 commit comments

Comments
 (0)