Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-08T15:58:27.797Z
Answers.Text: 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!!
Answers.UserDisplayName: Matthias
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-08T17:09:38.903Z
Answers.Text: 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.
Answers.UserDisplayName: Matthias
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-08T20:30:32.553Z
Answers.Text: Something must not be right -- it's saying the alias isn't defined. See the article for details.
Answers.UserDisplayName: andrew.welch
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-08T01:35:58.870Z
Answers.LastActivityDate: 2020-03-08T11:39:03.307Z
Answers.LastEditDate: 2020-03-08T11:39:03.307Z
Answers.UserDisplayName: andrew.welch
Body: <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>
  
Tags: <craft3><assets><siteurl>
Title: alternative global variable to siteUrl or the primary website?
ThreadText: # 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:
  
  ```php
  <?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' => [
          '@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](https://nystudio107.com/blog/multi-environment-configuration-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.  
  
  ---
  
  