<p>I also set up those two environment variables (totally custom variables, with the one specialty that they <a href="http://buildwithcraft.com/docs/multi-environment-configs#environment-specific-variables" rel="nofollow">are passed to the CP</a>)
for my multilibgual sites.</p>

<p>But I have both <code>basePath</code> and <code>baseUrl</code> <strong>combined for all my locales</strong>!</p>

<pre><code>'.dev' =&gt; array(
    'siteUrl' =&gt; array(
        'en' =&gt; 'http://local.mysite.dev/',
        'fr' =&gt; 'http://local.mysite.dev/fr/',
    ),
    'environmentVariables' =&gt; array(
        'basePath' =&gt; '/path-to-mysite/public/',
        'baseUrl' =&gt; 'http://local.mysite.dev/',
    )
)
</code></pre>

<p>I use these variables for two things:</p>

<ul>
<li><p>Make assets from local asset sources available to all my locales. I set them absolutely, because relative paths don't
do it in this case, as the path to the assets' folder and the URL is a different one from <a href="http://example.com/fr/" rel="nofollow">http://example.com/fr/</a> as it is from <a href="http://example.com/" rel="nofollow">http://example.com/</a>.</p></li>
<li><p>Build absolute URLs to static files from my templates, e.g.
<code>&lt;link rel="stylesheet" href="{{ craft.config.environmentVariables.baseUrl }}stylesheets/site.css" /&gt;</code>
Both, the <code>url()</code> function and the <code>siteUrl</code> variable don't work in this case, they always return the site's URL including the locale part.</p></li>
</ul>

<p>So it's basically just a way to build <strong>absolute</strong> URLs to Craft assets and files for me.</p>

<p>I'm actually not totally sure how much of this could be solved with <strong>root relative</strong> paths, but in my case I've also
at least one environment where the path from web root to the craft site is differently to my other environments.</p>

<p>(For testing sites on mobile devices where I can't set virtual domains, I have an environment to access the site via the
local machine's IP address. As there's multiple sites on that machine, they are all in subfolders under web root.)</p>

CC BY-SA 3.0
2015-08-24T18:21:16.453Z
Thanks @carlcs!
I've got everything set up & working fine. I was more curious than anything; wanted to see if there was a way I hadn't thought of.
Damon
CC BY-SA 3.0
2015-08-24T18:36:06.140Z
Vote for this [feature request](http://feedback.buildwithcraft.com/forums/285221-feature-requests/suggestions/9469227-a-siteurl-variable-without-the-locale-part) I just posted and we might get a new way. :)
carlcs
CC BY-SA 3.0
2015-08-24T18:07:53.273Z
2015-08-24T18:15:38.157Z
2015-08-24T18:15:38.157Z
carlcs
<p>Maybe it's an ugly solution but I wanted to keep using only the siteUrl variable, so I added this to my _layout.html</p>

<pre><code>{% if '/fr/' in siteUrl %}
  {% set siteUrl = siteUrl|slice(length, -3) %}
{% endif %}
</code></pre>

<p>So the siteUrl will return the URL defined in the settings, without the "fr/".</p>

CC BY-SA 4.0
2018-06-20T08:33:58.830Z
2018-06-20T08:33:58.830Z
Janos Filip
<p>I am setting up a multi-language site so far so good - everything is pretty obvious what to do.</p>

<p>I am curious if there is a way/best practice to have the <code>environmentVariables</code> array configured so that it knows which key to use based on the current <code>siteUrl</code> key?</p>

<p>I realize the syntax is incorrect/wrong but this is just an example:</p>

<pre><code>'.dev' =&gt; array(
    'siteUrl' =&gt; array(
        'en' =&gt; 'http://local.mysite.dev/',
        'fr' =&gt; 'http://local.mysite.dev/fr/',
    ),
    'environmentVariables' =&gt; array(
        'en' =&gt; array(
            'basePath' =&gt; '/path-to-mysite/public/',
            'baseUrl' =&gt; 'http://local.mysite.dev/',
         ),
        'fr' =&gt; array(
            'basePath' =&gt; '/path-to-mysite/public/fr/',
            'baseUrl' =&gt; 'http://local.mysite.dev/fr/',
        )
    )
)
</code></pre>

<p>Or, is that something I just append to any path(s) in my template given the current section/segment etc?</p>

<localization><config>
Localized Environment Variables Based On siteUrl?
# Localized Environment Variables Based On siteUrl?

(Asked by: username_0 on 2015-08-24)

I am setting up a multi-language site so far so good - everything is pretty obvious what to do.
I am curious if there is a way/best practice to have the environmentVariables array configured so that it knows which key to use based on the current siteUrl key?
I realize the syntax is incorrect/wrong but this is just an example:
'.dev' => array(
    'siteUrl' => array(
        'en' => 'http://local.mysite.dev/',
        'fr' => 'http://local.mysite.dev/fr/',
    ),
    'environmentVariables' => array(
        'en' => array(
            'basePath' => '/path-to-mysite/public/',
            'baseUrl' => 'http://local.mysite.dev/',
         ),
        'fr' => array(
            'basePath' => '/path-to-mysite/public/fr/',
            'baseUrl' => 'http://local.mysite.dev/fr/',
        )
    )
)

Or, is that something I just append to any path(s) in my template given the current section/segment etc?

**Tags:** localization, config

---

## 2 answers

### Answer by username_1 on 2015-08-24. Score: 3 | Accepted answer

I also set up those two environment variables (totally custom variables, with the one specialty that they are passed to the CP)
for my multilibgual sites.
But I have both basePath and baseUrl combined for all my locales!
'.dev' => array(
    'siteUrl' => array(
        'en' => 'http://local.mysite.dev/',
        'fr' => 'http://local.mysite.dev/fr/',
    ),
    'environmentVariables' => array(
        'basePath' => '/path-to-mysite/public/',
        'baseUrl' => 'http://local.mysite.dev/',
    )
)

I use these variables for two things:

Make assets from local asset sources available to all my locales. I set them absolutely, because relative paths don't
do it in this case, as the path to the assets' folder and the URL is a different one from http://example.com/fr/ as it is from http://example.com/.
Build absolute URLs to static files from my templates, e.g.

Both, the url() function and the siteUrl variable don't work in this case, they always return the site's URL including the locale part.

So it's basically just a way to build absolute URLs to Craft assets and files for me.
I'm actually not totally sure how much of this could be solved with root relative paths, but in my case I've also
at least one environment where the path from web root to the craft site is differently to my other environments.
(For testing sites on mobile devices where I can't set virtual domains, I have an environment to access the site via the
local machine's IP address. As there's multiple sites on that machine, they are all in subfolders under web root.)

> **Comments:**
> **username_0**: Thanks @carlcs! I've got everything set up & working fine. I was more curious than anything; wanted to see if there was a way I hadn't thought of.  
> **username_1**: Vote for this [feature request](http://feedback.buildwithcraft.com/forums/285221-feature-requests/suggestions/9469227-a-siteurl-variable-without-the-locale-part) I just posted and we might get a new way. :)  

---

### Answer by username_2 on 2018-06-20. Score: 1

Maybe it's an ugly solution but I wanted to keep using only the siteUrl variable, so I added this to my _layout.html
{% if '/fr/' in siteUrl %}
  {% set siteUrl = siteUrl|slice(length, -3) %}
{% endif %}

So the siteUrl will return the URL defined in the settings, without the "fr/".


---

