surgems / env-condition
Statamic Tag that only displays it's content in a selected environment.
README
Env Condition is a Statamic Modifier that only displays it's content in a selected environment.
Features
This addon does:
- Allows you to display content/fields based on the
APP_ENV
.
How to Install
You can use this addon by running the following command from your project root:
composer require surgems/env-condition
How to Use
This addons uses 3 environments:
- local
- staging
- production
Tag
You can display content inside the tag depending on the condition of the APP_ENV
.
There are 2 tag Methods:
{{ if_env env="local" }} {{ content | widont }} {{ /if_env }}
This would display the content inside the tags if the APP_ENV
IS 'local'.
{{ if_env:not env="local" }} {{ content | widont }} {{ /if_env:not }}
This would display the content inside the tags if the APP_ENV
IS NOT 'local'.
You can also add multiple parameters:
{{ if_env:not env="local|staging" }} {{ content | widont }} {{ /if_env:not }}
This would display the content inside the tags if the APP_ENV
IS NOT 'local' OR 'staging'.
Modifier
You can display a field whenever the APP_ENV
is a certain environment.
There are 2 modifiers:
{{ field | if_env:local }}
This would display the field content if the APP_ENV
IS equal to 'local'.
{{ field | if_env_not:local }}
This would display the field content if the APP_ENV
IS NOT equal to 'local'.
You can also add multiple parameters:
{{ field | if_env:local:staging }}