<p>I'd like to use @webroot in my templates using the <code>{{ alias('@webroot') }}</code> tag. However, when I do this it returns a longer path than what is returned when I use @webroot in the control panel.</p>

<p>For instance, I generate asset paths using @webroot in a control panel field. This works well: in my local dev environment, the path is referenced correctly from the root of my local web server. However, when I use the alias tag directly in a template, the path begins instead at my local hard drive. </p>

<p>I've tried to override this using an environment variable: <code>WEB_ROOT="/xxx/web/"</code> and then referencing it in the config:</p>

<pre><code>'aliases' =&gt; [
   '@webroot' =&gt; getenv('WEB_ROOT'),
],
</code></pre>

<p>But it that doesn't seem to do anything. Even if I change the path to <code>'hi'</code>, both instances of @webroot remain the same. The assets using the @webroot path generated from the control panel continue to work (referenced from my web server) and the template continues to render the longer path (referenced from my local HD).</p>

<p>What am I missing here? Is there a cache that needs to be refreshed? </p>

CC BY-SA 4.0
2020-01-10T10:47:22.720Z
Are you setting the aliases in the correct environment in your `config/general.php`?
Oli
CC BY-SA 4.0
2020-01-10T14:35:02.533Z
@Oli, yes. I was able to create a new, custom alias with help from this post: https://craftcms.stackexchange.com/questions/29724/invalid-path-alias (remove the @ symbol), which does what I need it to. But still not able to override the webroot alias.
Lauren
<environmentvariables><environments><alias>
Using @webroot in templates returns a different path, can't override in config
# Using @webroot in templates returns a different path, can't override in config

(Asked by: username_0 on 2020-01-10)

I'd like to use @webroot in my templates using the {{ alias('@webroot') }} tag. However, when I do this it returns a longer path than what is returned when I use @webroot in the control panel.
For instance, I generate asset paths using @webroot in a control panel field. This works well: in my local dev environment, the path is referenced correctly from the root of my local web server. However, when I use the alias tag directly in a template, the path begins instead at my local hard drive. 
I've tried to override this using an environment variable: WEB_ROOT="/xxx/web/" and then referencing it in the config:
'aliases' => [
   '@webroot' => getenv('WEB_ROOT'),
],

But it that doesn't seem to do anything. Even if I change the path to 'hi', both instances of @webroot remain the same. The assets using the @webroot path generated from the control panel continue to work (referenced from my web server) and the template continues to render the longer path (referenced from my local HD).
What am I missing here? Is there a cache that needs to be refreshed?

**Tags:** environmentvariables, environments, alias

> **Comments:**
> **username_1**: Are you setting the aliases in the correct environment in your `config/general.php`?  
> **username_0**: @username_1, yes. I was able to create a new, custom alias with help from this post: https://craftcms.stackexchange.com/questions/29724/invalid-path-alias (remove the @ symbol), which does what I need it to. But still not able to override the webroot alias.  

---

## 0 answers

