1

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?

2
  • Are you setting the aliases in the correct environment in your config/general.php?
    – Oli
    Jan 10 '20 at 10:47
  • @Oli, yes. I was able to create a new, custom alias with help from this post: 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
    Jan 10 '20 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.