<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>

CC BY-SA 4.0
2020-10-25T09:33:51.570Z
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
Urs
CC BY-SA 4.0
2020-10-25T09:35:15.513Z
aha https://github.com/craftcms/cms/issues/4098
Urs
CC BY-SA 4.0
2020-10-25T09:38:02.743Z
`{% set baseUrl = craft.app.sites.currentSite.getBaseUrl()%}` works for me
Urs
CC BY-SA 4.0
2019-02-12T15:03:00.590Z
2019-02-12T15:03:00.590Z
Oli
<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>

<craft3><environmentvariables>
baseUrl outputs environment variable
# 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 %}
  {{ site.language }}
{% 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 and passing it a siteId parameter. So do:
{% set sites = craft.app.sites.getAllSites() | without(currentSite) %}
{% for site in sites %}
   {{ site.language }}
{% 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  

---

