Answers.Body: <p>Everything is set up properly after all. I just wasn't referencing the actual image, but rather its parent record. Correct syntax in this context should have been:</p>
  <pre><code>{{ print.printImage.first().getUrl() }}
  </code></pre>
  <p>Feel free to delete this post, or leave it for the config details.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2014-09-19T00:02:21.470Z
Answers.LastActivityDate: 2021-03-03T13:03:13.260Z
Answers.LastEditDate: 2021-03-03T13:03:13.260Z
Answers.UserDisplayName: Douglas McDonald
Body: <p>I'm having a problem getting my asset URLs to print properly in templates. The site is using a multi-environment configuration (dev/stage/live) with localized content (en/es/da) and shared assets. Here are the config and settings.</p>
  
  <p>In the config file:</p>
  
  <pre><code>define('SITE_URL', URI_SCHEME . $_SERVER['SERVER_NAME'] . '/');
  define('BASEPATH', realpath(CRAFT_BASE_PATH . '/../') . '/');
  
  return array(
      '*' =&gt; array(
          // common config settings
      ),
      'site.craft.dev' =&gt; array(
          'siteUrl' =&gt; array(
              'en' =&gt; 'http://site.craft.dev:8888/',
              'es' =&gt; 'http://site.craft.dev:8888/es/',
              'da' =&gt; 'http://site.craft.dev:8888/da/',
          ),
          'environmentVariables' =&gt; array(
              'baseUrl'  =&gt; 'http://site.craft.dev:8888/',
              'basePath' =&gt; BASEPATH . 'http/',
          ),
      ),
      'stage.site.com'  =&gt; array(
          // etc
      ),
      'site.com'  =&gt; array(
          // etc
      ), 
  );
  </code></pre>
  
  <p>In the CP:</p>
  
  <p>I have an 'Images' asset source defined with:</p>
  
  <ul>
  <li><p>File System Path: {basePath}assets/img/</p></li>
  <li><p>URL: /assets/img/</p></li>
  </ul>
  
  <p>I have a 'printImage' asset field defined with:</p>
  
  <ul>
  <li>Upload Location: Images (selected in dropdown); prints (in field)</li>
  </ul>
  
  <p>Uploading images through the CP works great, and images go to the correct folder, and are viewable in the CP.</p>
  
  <p>In the template (and here is the problem), when I request the image url using {{ printImage.url }} it outputs:</p>
  
  <ul>
  <li><a href="http://site.craft.dev:8888/prints/imagename.jpg" rel="nofollow">http://site.craft.dev:8888/prints/imagename.jpg</a></li>
  </ul>
  
  <p>when it should be:</p>
  
  <ul>
  <li><a href="http://site.craft.dev:8888/assets/img/prints/imagename.jpg" rel="nofollow">http://site.craft.dev:8888/assets/img/prints/imagename.jpg</a></li>
  </ul>
  
  <p>Also, when I switch to another language it outputs:</p>
  
  <ul>
  <li><a href="http://site.craft.dev:8888/es/prints/imagename.jpg" rel="nofollow">http://site.craft.dev:8888/es/prints/imagename.jpg</a></li>
  </ul>
  
  <p>It seems to be missing the portion of the path defined in Settings:Assets:Sources:'Images', and also is including the localization prefix.</p>
  
  <p>All other paths and URLs in the site are working perfectly. Anyone have any ideas where I'm going wrong with assets? I guess I don't understand how it's crafting the asset URLs. Should I be defining an 'assetsPath' in my environment variables?</p>
  
  <p>Thank you!</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-06-09T09:58:38.987Z
Comments.Text: This is a great question and it comes up in my searches all the time. I only wish you had waited for an answer. There's no canonical documentation (that I know of) for setting asset paths in Craft and it's a major source of error and frustration for me.
Comments.UserDisplayName: David Rhoden
Tags: <assets><url><config>
Title: How do I properly set assets paths?
ThreadText: # How do I properly set assets paths?
  
  (Asked by: username_0 on 2014-09-18)
  
  I'm having a problem getting my asset URLs to print properly in templates. The site is using a multi-environment configuration (dev/stage/live) with localized content (en/es/da) and shared assets. Here are the config and settings.
  
  In the config file:
  
  ```
  define('SITE_URL', URI_SCHEME . $_SERVER['SERVER_NAME'] . '/');
  define('BASEPATH', realpath(CRAFT_BASE_PATH . '/../') . '/');
  
  return array(
      '*' => array(
          // common config settings
      ),
      'site.craft.dev' => array(
          'siteUrl' => array(
              'en' => 'http://site.craft.dev:8888/',
              'es' => 'http://site.craft.dev:8888/es/',
              'da' => 'http://site.craft.dev:8888/da/',
          ),
          'environmentVariables' => array(
              'baseUrl'  => 'http://site.craft.dev:8888/',
              'basePath' => BASEPATH . 'http/',
          ),
      ),
      'stage.site.com'  => array(
          // etc
      ),
      'site.com'  => array(
          // etc
      ), 
  );
  
  ```
  
  In the CP:
  
  I have an 'Images' asset source defined with:
  
  * File System Path: {basePath}assets/img/
  * URL: /assets/img/
  
  I have a 'printImage' asset field defined with:
  
  * Upload Location: Images (selected in dropdown); prints (in field)
  
  Uploading images through the CP works great, and images go to the correct folder, and are viewable in the CP.
  
  In the template (and here is the problem), when I request the image url using {{ printImage.url }} it outputs:
  
  * <http://site.craft.dev:8888/prints/imagename.jpg>
  
  when it should be:
  
  * <http://site.craft.dev:8888/assets/img/prints/imagename.jpg>
  
  Also, when I switch to another language it outputs:
  
  * <http://site.craft.dev:8888/es/prints/imagename.jpg>
  
  It seems to be missing the portion of the path defined in Settings:Assets:Sources:'Images', and also is including the localization prefix.
  
  All other paths and URLs in the site are working perfectly. Anyone have any ideas where I'm going wrong with assets? I guess I don't understand how it's crafting the asset URLs. Should I be defining an 'assetsPath' in my environment variables?
  
  Thank you!
  
  **Tags:** assets, url, config
  
  > **Comments:**
  > **username_1**: This is a great question and it comes up in my searches all the time. I only wish you had waited for an answer. There's no canonical documentation (that I know of) for setting asset paths in Craft and it's a major source of error and frustration for me.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2014-09-19. Score: 4 | Accepted answer
  
  Everything is set up properly after all. I just wasn't referencing the actual image, but rather its parent record. Correct syntax in this context should have been:
  
  ```
  {{ print.printImage.first().getUrl() }}
  
  ```
  
  Feel free to delete this post, or leave it for the config details.
  
  
  ---
  
  