Skip to content

Conversation

@brandonkelly
Copy link
Member

@brandonkelly brandonkelly commented Aug 28, 2025

Description

  • craft\helpers\App::env() now supports parsing nested environment variables, e.g. FOO="bar/${BAZ}".
  • craft\helpers\App::parseEnv() now supports parsing nested environment variables using the …/$NAME/… and …${NAME}… syntaxes anywhere within the passed-in string (not just beginning with $NAME/…).
  • CRAFT_SITE and CRAFT_SITE_UPPER environment variables are now defined when the current site is determined.
    • CRAFT_SITE is set to the site’s handle.
    • CRAFT_SITE_UPPER is set to the site’s handle, converted to UPPER_SNAKE_CASE.

So for example, it’s now possible to define per-site API token environment variables, such as:

API_KEY_EN=xxxxxx
API_KEY_DE=yyyyyy
API_KEY_NL=zzzzzz

…and then reference each of them dynamically, depending on the current site, by setting an API token setting to:

$API_KEY_${CRAFT_SITE_UPPER}`.

Related issues

@brandonkelly brandonkelly force-pushed the feature/env-improvements branch from 1631a16 to 397541c Compare August 28, 2025 23:10
@brandonkelly brandonkelly force-pushed the feature/env-improvements branch from 07bdbfc to 787431d Compare August 30, 2025 00:01
@brandonkelly brandonkelly merged commit ec914d0 into 5.9 Aug 30, 2025
@brandonkelly brandonkelly deleted the feature/env-improvements branch August 30, 2025 01:44
brandonkelly added a commit that referenced this pull request Oct 15, 2025
brandonkelly added a commit that referenced this pull request Oct 15, 2025
brandonkelly added a commit that referenced this pull request Oct 15, 2025
@brandonkelly brandonkelly mentioned this pull request Oct 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants