<p>For the entry URI format, you can use Twig, so you can include environment variables in the URL of an entry:</p>
<pre><code>{{ getenv('CURRENT_THEME') }}/{slug}
</code></pre>
<p>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.</p>
<p>What exactly do you mean by temporary skin, just a different set of CSS/JS assets?</p>
<p>Depending on how much your themes differ, here are a couple of options to display different themes:</p>
<ol>
<li>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.</li>
<li>Define your temporary skin / theme as a <a href="https://craftcms.com/docs/3.x/sites.html" rel="nofollow noreferrer">new site</a>. Then you can freely use different URL and template settings.</li>
<li>Use a <a href="https://craftcms.com/docs/3.x/routing.html#advanced-routing-with-url-rules" rel="nofollow noreferrer">custom route</a> with a custom controller that loads existing entries based on the URL, but includes whatever modifications you want for your temporary theme.</li>
<li>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.</li>
</ol>
<p>The best solution depends on how different your themes / skins are and how temporary those changes are.</p>

CC BY-SA 4.0
2021-09-10T07:36:41.113Z
2021-09-10T07:36:41.113Z
MoritzLost
<p>Is there any way to use an environment variable in the URL and template path settings for sections?</p>
<p>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).</p>
<p>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.</p>

<templating><config><environmentvariables><alias>
Template URL/path alias
# Template URL/path alias

(Asked by: username_0 on 2021-09-09)

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.

**Tags:** templating, config, environmentvariables, alias


---

## 1 answers

### Answer by username_1 on 2021-09-10. Score: 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:

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.
Define your temporary skin / theme as a new site. Then you can freely use different URL and template settings.
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.
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.


---

