1

I'm not sure if I understand the alias concept entirely

So I want to create an alias.

I write a variable into my .env File:

SITE_URL_DE="http://hello.local"

Then I put it into my general.php File:

'*' => [
    //other settings as well here
    'aliases' => [
      '@myNewAlias' => getenv('SITE_URL_DE'),
    ],
  ],

Now I want to print it in my template:

{{ alias('@myNewAlias') }}

This results in:

Invalid path alias: @myNewAlias

But why?

2

You need to set it without an @

'*' => [
    'aliases' => [
        'myNewAlias' => getenv('SITE_URL_DE')
     ]
]

Then you can do

{{ alias('@myNewAlias') }}

or in PHP

Craft::getAlias('@myNewAlias');
0

Your Answer

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

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