<p>You can define whatever aliases/environment variables you like. In this case, I'd probably define an environment variable in my <code>.env</code> file like this:</p>

<pre><code>BASE_WEB=http://example.com
</code></pre>

<p>And then in <code>config/general.php</code> I'd add an alias:</p>

<pre class="lang-php prettyprint-override"><code>&lt;?php
/**
 * General Configuration
 *
 * All of your system's general configuration settings go in here. You can see a
 * list of the available settings in vendor/craftcms/cms/src/config/GeneralConfig.php.
 *
 * @see craft\config\GeneralConfig
 */

return [
    // Craft config settings from .env variables
    'aliases' =&gt; [
        '@baseWeb' =&gt; getenv('BASE_WEB'),
    ],
];

</code></pre>

<p>And then to use this in a template, you'd just do:</p>

<pre><code>{{ alias('@baseWeb/assets/css/main.css') }}
</code></pre>

<p>...and away you go. To learn more, check out the <a href="https://nystudio107.com/blog/multi-environment-configuration-for-craft-cms-3" rel="nofollow noreferrer">Flat Multi-Environment Config for Craft CMS 3</a> article.</p>

CC BY-SA 4.0
2020-03-08T15:58:27.797Z
thank you very much for this answer! I'm fairly new to craft and never really understood the env/alias-possibilities, so this article is really helpful! thanks again!!
Matthias
CC BY-SA 4.0
2020-03-08T17:09:38.903Z
mmh, I tried this approach but get "Invalid Argument – yii\base\InvalidArgumentException" (…) if ($throwException) {
            throw new InvalidArgumentException("Invalid path alias: $alias");
        }… but I did exactly as your example.
Matthias
CC BY-SA 4.0
2020-03-08T20:30:32.553Z
Something must not be right -- it's saying the alias isn't defined. See the article for details.
andrew.welch
CC BY-SA 4.0
2020-03-08T01:35:58.870Z
2020-03-08T11:39:03.307Z
2020-03-08T11:39:03.307Z
andrew.welch
<p>I am currently developing a multilingual craft website. To include assets like styles and scripts, I have so far built the URL following the pattern "{{ siteUrl }}/assets/css/main.css". </p>

<p>However, as soon as I change from German to English in the frontend of the website, the siteUrl changes, too, so that the styles and scripts can't be found anymore.</p>

<p>Is there another global variable, like {root_url} in expressionengine, which returns only the URL of the primary website or the root URL, regardless of the chosen language or site?</p>

<p>thanks!</p>

<craft3><assets><siteurl>
alternative global variable to siteUrl or the primary website?
# alternative global variable to siteUrl or the primary website?

(Asked by: username_0 on 2020-03-07)

I am currently developing a multilingual craft website. To include assets like styles and scripts, I have so far built the URL following the pattern "{{ siteUrl }}/assets/css/main.css".

However, as soon as I change from German to English in the frontend of the website, the siteUrl changes, too, so that the styles and scripts can't be found anymore.

Is there another global variable, like {root\_url} in expressionengine, which returns only the URL of the primary website or the root URL, regardless of the chosen language or site?

thanks!

**Tags:** craft3, assets, siteurl

---

## 1 answers

### Answer by username_1 on 2020-03-08. Score: 4

You can define whatever aliases/environment variables you like. In this case, I'd probably define an environment variable in my .env file like this:
BASE_WEB=http://example.com

And then in config/general.php I'd add an alias:
 [
        '@baseWeb' => getenv('BASE_WEB'),
    ],
];


And then to use this in a template, you'd just do:
{{ alias('@baseWeb/assets/css/main.css') }}

...and away you go. To learn more, check out the Flat Multi-Environment Config for Craft CMS 3 article.

> **Comments:**
> **username_0**: thank you very much for this answer! I'm fairly new to craft and never really understood the env/alias-possibilities, so this article is really helpful! thanks again!!  
> **username_0**: mmh, I tried this approach but get "Invalid Argument – yii\base\InvalidArgumentException" (…) if ($throwException) {             throw new InvalidArgumentException("Invalid path alias: $alias");         }… but I did exactly as your example.  
> **username_1**: Something must not be right -- it's saying the alias isn't defined. See the article for details.  

---

