Answers.Body: <p>Your example of setting the S3 "URL Prefix" setting to something dynamic won't work because there are only a few settings in the Control Panel that Craft parses for dynamic Twig content and that isn't one of them.  i.e. in an Asset Field's <a href="https://craftcms.com/docs/assets-fields#dynamic-subfolder-paths" rel="nofollow noreferrer">Upload Location</a>, Section Title/URL Formats, etc.</p>
  
  <p>Honestly, I don't think there currently is a way to do that in Craft 2.</p>
  
  <p>This should be possible in the upcoming <a href="https://craftcms.com/3" rel="nofollow noreferrer">Craft 3</a> by <a href="https://github.com/craftcms/docs/blob/master/en/configuration.md#overriding-volume-settings" rel="nofollow noreferrer">overriding the setting</a> in <code>config/volumes.php</code> and doing your dynamic logic from PHP.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-12T18:44:56.573Z
Answers.LastActivityDate: 2017-07-12T18:44:56.573Z
Answers.UserDisplayName: Brad Bell
Body: <p>I have found the section in settings where I can set the URL Prefix for an asset source using a CNAME and pointing to the relative S3 bucket where the file actually lives but I am using a multi site environment so I need the value of the URL Prefix to be dynamic.</p>
  
  <p>I have tried setting it to <code>assets.{{ craft()-&gt;request-&gt;getServerName() }}</code>, also have tried <code>assets.{% craft()-&gt;request-&gt;getServerName() %}</code>but that is what's getting spit out on the page (asset url as rendered on page looks like <code>assets.{% craft()-&gt;request-&gt;getServerName() %}images/home-banner.jpg</code>. </p>
  
  <p>How can I make Craft parse this field's dynamic value? The statement isn't parsed as it would be if it was in a Twig template.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-08-11T20:02:02.973Z
Comments.Text: I'm not sure about your complete setup and requirements, but maybe you could create a separate asset source for each prefix / subdomain?
Comments.UserDisplayName: Youniteus
Tags: <templating><assets><s3>
Title: Use subdomain for S3 assets in multi-site Craft installation
ThreadText: # Use subdomain for S3 assets in multi-site Craft installation
  
  (Asked by: username_0 on 2017-07-12)
  
  I have found the section in settings where I can set the URL Prefix for an asset source using a CNAME and pointing to the relative S3 bucket where the file actually lives but I am using a multi site environment so I need the value of the URL Prefix to be dynamic.
  
  I have tried setting it to `assets.{{ craft()->request->getServerName() }}`, also have tried `assets.{% craft()->request->getServerName() %}`but that is what's getting spit out on the page (asset url as rendered on page looks like `assets.{% craft()->request->getServerName() %}images/home-banner.jpg`.
  
  How can I make Craft parse this field's dynamic value? The statement isn't parsed as it would be if it was in a Twig template.
  
  **Tags:** templating, assets, s3
  
  > **Comments:**
  > **username_1**: I'm not sure about your complete setup and requirements, but maybe you could create a separate asset source for each prefix / subdomain?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2017-07-12. Score: 1
  
  Your example of setting the S3 "URL Prefix" setting to something dynamic won't work because there are only a few settings in the Control Panel that Craft parses for dynamic Twig content and that isn't one of them. i.e. in an Asset Field's [Upload Location](https://craftcms.com/docs/assets-fields#dynamic-subfolder-paths), Section Title/URL Formats, etc.
  
  Honestly, I don't think there currently is a way to do that in Craft 2.
  
  This should be possible in the upcoming [Craft 3](https://craftcms.com/3) by [overriding the setting](https://github.com/craftcms/docs/blob/master/en/configuration.md#overriding-volume-settings) in `config/volumes.php` and doing your dynamic logic from PHP.
  
  
  ---
  
  