1

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.

  • I'm not sure about your complete setup and requirements, but maybe you could create a separate asset source for each prefix / subdomain? – Youniteus Aug 11 '17 at 20:02
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, 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 by overriding the setting in config/volumes.php and doing your dynamic logic from PHP.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.