Answers.Body: <p>You can get it to return the url using the <a href="https://docs.craftcms.com/v3/dev/functions.html#siteurl-path-params-scheme-siteid" rel="nofollow noreferrer">siteUrl function</a> and passing it a <code>siteId</code> parameter. So do:</p>
  
  <pre><code>{% set sites = craft.app.sites.getAllSites() | without(currentSite) %}
  {% for site in sites %}
     &lt;li&gt;&lt;a href="{{ siteUrl(siteId=site.id) }}" title="{{ site.language }}"&gt;{{ site.language }}&lt;/a&gt;&lt;/li&gt;
  {% endfor %}
  </code></pre>
  
  <p>I don't know if it's the best way but it works :)</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-25T09:33:51.570Z
Answers.Text: But what is the reason for the above behaviour? Outputting `craft.app.sites` gives me `[baseUrl] => '$BASE_URL_DE'` , it's like the env var is not being parsed
Answers.UserDisplayName: Urs
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-25T09:35:15.513Z
Answers.Text: aha https://github.com/craftcms/cms/issues/4098
Answers.UserDisplayName: Urs
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-25T09:38:02.743Z
Answers.Text: `{% set baseUrl = craft.app.sites.currentSite.getBaseUrl()%}` works for me
Answers.UserDisplayName: Urs
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-12T15:03:00.590Z
Answers.LastActivityDate: 2019-02-12T15:03:00.590Z
Answers.UserDisplayName: Oli
Body: <p>The newer versions of Craft CMS stimulate using environment variables in the CP. It works perfectly. I have set two variables for sites in my .env file:</p>
  
  <pre><code>DUTCH_SITE_URL="http://company.test"
  ENGLISH_SITE_URL="http://company.test/en"
  </code></pre>
  
  <p>One thing that's not clear to me is the right way to request the baseUrl in templates. For example: I'm using a simple language switcher to switch between two languages:</p>
  
  <pre><code>{% set sites = craft.app.sites.getAllSites() | without(currentSite) %}
  {% for site in sites %}
    &lt;li&gt;&lt;a href="{{ site.baseUrl }}" title="{{ site.language }}"&gt;{{ site.language }}&lt;/a&gt;&lt;/li&gt;
  {% endfor %}
  </code></pre>
  
  <p>When viewing the Dutch website the language switcher shows the link to the English website. The problem is that site.baseUrl outputs the environment variables instead of the English site url. The link looks like this:</p>
  
  <pre><code>http://company.test/$ENGLISH_SITE_URL
  </code></pre>
  
  <p>What's the proper way to deal with this?</p>
  
Tags: <craft3><environmentvariables>
Title: baseUrl outputs environment variable
ThreadText: # baseUrl outputs environment variable
  
  (Asked by: username_0 on 2019-02-12)
  
  The newer versions of Craft CMS stimulate using environment variables in the CP. It works perfectly. I have set two variables for sites in my .env file:
  
  ```
  DUTCH_SITE_URL="http://company.test"
  ENGLISH_SITE_URL="http://company.test/en"
  
  ```
  
  One thing that's not clear to me is the right way to request the baseUrl in templates. For example: I'm using a simple language switcher to switch between two languages:
  
  ```
  {% set sites = craft.app.sites.getAllSites() | without(currentSite) %}
  {% for site in sites %}
    <li><a href="{{ site.baseUrl }}" title="{{ site.language }}">{{ site.language }}</a></li>
  {% endfor %}
  
  ```
  
  When viewing the Dutch website the language switcher shows the link to the English website. The problem is that site.baseUrl outputs the environment variables instead of the English site url. The link looks like this:
  
  ```
  http://company.test/$ENGLISH_SITE_URL
  
  ```
  
  What's the proper way to deal with this?
  
  **Tags:** craft3, environmentvariables
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-02-12. Score: 2 | Accepted answer
  
  You can get it to return the url using the [siteUrl function](https://docs.craftcms.com/v3/dev/functions.html#siteurl-path-params-scheme-siteid) and passing it a `siteId` parameter. So do:
  
  ```
  {% set sites = craft.app.sites.getAllSites() | without(currentSite) %}
  {% for site in sites %}
     <li><a href="{{ siteUrl(siteId=site.id) }}" title="{{ site.language }}">{{ site.language }}</a></li>
  {% endfor %}
  
  ```
  
  I don't know if it's the best way but it works :)
  
  > **Comments:**
  > **username_2**: But what is the reason for the above behaviour? Outputting `craft.app.sites` gives me `[baseUrl] => '$BASE_URL_DE'` , it's like the env var is not being parsed  
  > **username_2**: aha https://github.com/craftcms/cms/issues/4098  
  > **username_2**: `{% set baseUrl = craft.app.sites.currentSite.getBaseUrl()%}` works for me  
  
  ---
  
  