Answers.Body: <p>The easiest way to do this would be to just use root-relative resource URLs:</p>
  
  <pre><code>&lt;link rel="stylesheet" type="text/css" href="/assets/css/styles.css"&gt;
  &lt;script type="text/javascript src="/assets/js/scripts.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>The only disadvantage of that is it makes your site slightly less portable – you wouldn’t be able to run it from a subdirectory on a web server without updating all your URLs in the templates.</p>
  
  <p>So a better option would be to define a custom config variable that holds the value of your site’s base URL in craft/config/general.php;</p>
  
  <pre><code>return array(
      'omitScriptNameInUrls' =&gt; true,
  
      'siteUrl' =&gt; array(
          'nl' =&gt; 'http://krycer.be/nl/',
          'fr' =&gt; 'http://krycer.be/fr/',
      ),
  
      'baseUrl' =&gt; 'http://krycer.be/',
  ),
  </code></pre>
  
  <p>And then access that config setting from your templates via <a href="http://buildwithcraft.com/docs/templating/craft.config" rel="noreferrer">craft.config</a>:</p>
  
  <pre><code>&lt;link rel="stylesheet" type="text/css" href="{{ craft.config.baseUrl }}assets/css/styles.css"&gt;
  &lt;script type="text/javascript src="{{ craft.config.baseUrl }}assets/js/scripts.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>Note that there’s no reason to place that custom config variable within the <a href="http://buildwithcraft.com/docs/config-settings#environmentVariables" rel="noreferrer">environmentVariables</a> config setting. The top level of the config array will work just fine for this.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-02T20:42:56.590Z
Answers.Text: That solution did it for me indeed. The root-relative didn't work everywhere. For some reason it worked on images but not on javascript files. Very strange. 
  
  And when adding custom URI's to my sections such as "customSegment/{slug}" it didn't work either as the root was relative to my index.php in my language subfolders.
  
  But problem solved! Thanks.
Answers.UserDisplayName: Tom De Smet
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-01T21:06:13.273Z
Answers.LastActivityDate: 2014-11-01T21:06:13.273Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>I have a multilingual website which has a folder structure such as:</p>
  
  <pre><code>craft
  assets
    js
    css
  nl
  fr
  </code></pre>
  
  <p>My goal is to link to the assets folder for my js en css files, but as I'm running a multilingual site I have set my config file to:</p>
  
  <pre><code>return array(
      'omitScriptNameInUrls' =&gt; true,
  
      'siteUrl' =&gt; array(
          'nl' =&gt; 'http://krycer.be/nl/',
          'fr' =&gt; 'http://krycer.be/fr/',
      ),
  );
  </code></pre>
  
  <p>Which means that my {{ siteUrl }} is set to krycer.be/nl or krycer.be/fr
  But my assets folder is one level higher.
  I tried adding this code to the config.php:</p>
  
  <pre><code>'environmentVariables' =&gt; array(
      'baseUrl'  =&gt; 'http://krycer.be/',
  ),
  </code></pre>
  
  <p>and accessing it by using</p>
  
  <pre><code>{{ baseUrl }} or {{ craft.config.environmentVariables.baseUrl }}
  </code></pre>
  
  <p>But nothing seems to work. How can I create an abolute link to my assets folder?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-11-01T18:13:56.527Z
Comments.Text: I think I found a solution elsewhere. It seems you can define your own variables in the general.php file and get to them through Craft.config.variableName.
  
  That solved it for me. Let me know if it's the right solution or if there are better ones!
Comments.UserDisplayName: Tom De Smet
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-11-01T20:08:29.730Z
Comments.Text: `general.php` is the place to do this Tom.  What config file are you referring to in your question?  Most of the code you have there would be in your general.php file, no?
Comments.UserDisplayName: Ben Parizek
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-11-02T20:40:44.940Z
Comments.Text: Idd, I was referring to the general.php file :)
Comments.UserDisplayName: Tom De Smet
Tags: <localization><config>
Title: Custom environment variable to main assets folder
ThreadText: # Custom environment variable to main assets folder
  
  (Asked by: username_0 on 2014-11-01)
  
  I have a multilingual website which has a folder structure such as:
  
  ```
  craft
  assets
    js
    css
  nl
  fr
  
  ```
  
  My goal is to link to the assets folder for my js en css files, but as I'm running a multilingual site I have set my config file to:
  
  ```
  return array(
      'omitScriptNameInUrls' => true,
  
      'siteUrl' => array(
          'nl' => 'http://krycer.be/nl/',
          'fr' => 'http://krycer.be/fr/',
      ),
  );
  
  ```
  
  Which means that my {{ siteUrl }} is set to krycer.be/nl or krycer.be/fr
  But my assets folder is one level higher.
  I tried adding this code to the config.php:
  
  ```
  'environmentVariables' => array(
      'baseUrl'  => 'http://krycer.be/',
  ),
  
  ```
  
  and accessing it by using
  
  ```
  {{ baseUrl }} or {{ craft.config.environmentVariables.baseUrl }}
  
  ```
  
  But nothing seems to work. How can I create an abolute link to my assets folder?
  
  **Tags:** localization, config
  
  > **Comments:**
  > **username_0**: I think I found a solution elsewhere. It seems you can define your own variables in the general.php file and get to them through Craft.config.variableName.  That solved it for me. Let me know if it's the right solution or if there are better ones!  
  > **username_1**: `general.php` is the place to do this Tom.  What config file are you referring to in your question?  Most of the code you have there would be in your general.php file, no?  
  > **username_0**: Idd, I was referring to the general.php file :)  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2014-11-01. Score: 6 | Accepted answer
  
  The easiest way to do this would be to just use root-relative resource URLs:
  
  ```
  <link rel="stylesheet" type="text/css" href="/assets/css/styles.css">
  <script type="text/javascript src="/assets/js/scripts.js"></script>
  
  ```
  
  The only disadvantage of that is it makes your site slightly less portable – you wouldn’t be able to run it from a subdirectory on a web server without updating all your URLs in the templates.
  
  So a better option would be to define a custom config variable that holds the value of your site’s base URL in craft/config/general.php;
  
  ```
  return array(
      'omitScriptNameInUrls' => true,
  
      'siteUrl' => array(
          'nl' => 'http://krycer.be/nl/',
          'fr' => 'http://krycer.be/fr/',
      ),
  
      'baseUrl' => 'http://krycer.be/',
  ),
  
  ```
  
  And then access that config setting from your templates via [craft.config](http://buildwithcraft.com/docs/templating/craft.config):
  
  ```
  <link rel="stylesheet" type="text/css" href="{{ craft.config.baseUrl }}assets/css/styles.css">
  <script type="text/javascript src="{{ craft.config.baseUrl }}assets/js/scripts.js"></script>
  
  ```
  
  Note that there’s no reason to place that custom config variable within the [environmentVariables](http://buildwithcraft.com/docs/config-settings#environmentVariables) config setting. The top level of the config array will work just fine for this.
  
  > **Comments:**
  > **username_0**: That solution did it for me indeed. The root-relative didn't work everywhere. For some reason it worked on images but not on javascript files. Very strange.   And when adding custom URI's to my sections such as "customSegment/{slug}" it didn't work either as the root was relative to my index.php in my language subfolders.  But problem solved! Thanks.  
  
  ---
  
  