Skip to content

Latest commit

 

History

History
56 lines (47 loc) · 2.58 KB

how-to-use.md

File metadata and controls

56 lines (47 loc) · 2.58 KB

How to use Environment Awareness

Configure your environments

  1. Define a unique SS_ENVIRONMENT_LABEL environmental variable in each of your environments:
SS_ENVIRONMENT_LABEL="Production"
  1. Configure properties for each of these environments in your project config yml, grouped by their labels:
---
name: my-environment-awareness
after: environment-awareness
---
JonoM\EnvironmentAwareness\EnvironmentAwareness:
  environments:
    Development:
      short_label: 'DEV' # Used in CMS when side menu is collapsed
      color: '#f26522'
      description: 'Local development site'
    Production:
      short_label: 'PROD'
      color: '#00a651'
      description: 'Live website'
  1. Flush the config manifest

Tip: The labels 'Development', 'Stage' and 'Production' have pre-defined colours and descriptions, so you can use these without additional configuration if you like.

Note: Silverstripe has a concept of 'environment type' (SS_ENVIRONMENT_TYPE) which can be set to 'live', 'test' or 'dev'. This is more like a 'mode' than a type though, because there is nothing to stop you temporarily setting your production environment type to 'dev' to get some debugging information, or your development environment to 'live' to simulate production configuration locally. So you can't really on the environment type to know which server environment you're interacting with. SS_ENVIRONMENT_LABEL is intended to be a genuine constant, so you can have clarity about which environment you are working on.

Include front-end environment notice

Option 1: Include the environment notice template at the top of the body in Page.ss:

<% include JonoM\\EnvironmentAwareness\\EnvironmentNotice %>

Option 2: If you have BetterNavigator installed, you can augment that component by adding this include anywhere in the body of Page.ss:

<% include JonoM\\EnvironmentAwareness\\BetterNavigator_Environment %>

Only show notice to developers

If you only have two environments (local and live), you probably don't need all of your CMS users to see environment notices. You can indicate individual Members that should see the notices like so:

---
name: my-environment-awareness
after: environment-awareness
---
JonoM\EnvironmentAwareness\EnvironmentAwareness:
  Members:
    - [email protected]
    - [email protected]