Is there any way to use an environment variable in the URL and template path settings for sections?

We are prototyping a site with a temporary skin running alongside our front-end build but would ideally like content for both delivered via the same section in the CMS (without having to consume via Element API or Graph QL).

Appreciate any thoughts on whether this is possible - IO had tried to set an alias in the general config but this wasn't recognised by the Craft template controller.

1 Answer 1


For the entry URI format, you can use Twig, so you can include environment variables in the URL of an entry:

{{ getenv('CURRENT_THEME') }}/{slug}

However, the entry URI is parsed when the entry is saved, not dynamically for every request. Furthermore, the template setting does not support dynamic paths.

What exactly do you mean by temporary skin, just a different set of CSS/JS assets?

Depending on how much your themes differ, here are a couple of options to display different themes:

  1. Use a query parameter or a custom lightswitch field in user accounts to switch between themes. Then you can modify your templates to output the correct set of assets (and any other modifications you may want to include) depending on that parameter / setting.
  2. Define your temporary skin / theme as a new site. Then you can freely use different URL and template settings.
  3. Use a custom route with a custom controller that loads existing entries based on the URL, but includes whatever modifications you want for your temporary theme.
  4. If you are just working on the temporary theme to replace the current theme at some point: Instead of switching themes in a single Craft installation, create a separate branch in your Git repository and deploy that in a staging environment. This gives you a playground to test out ideas before they go live.

The best solution depends on how different your themes / skins are and how temporary those changes are.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.