v2-hub icon indicating copy to clipboard operation
v2-hub copied to clipboard

{{ theme:asset }} always outputs absolute urls

Open wanze opened this issue 4 years ago • 2 comments

Describe the bug

According to the docs, the {{ asset }} tag should output relative urls by default. However, it outputs full urls.

To Reproduce

  1. Add the following tag in your template: {{ theme:asset src="assets/app.js" }}
  2. Check the source code

You'll see that the asset is referenced absolute: https://mydomain.com/themes/mytheme/assets/app.js

Expected behavior

The url to the asset should be relative (/themes/mytheme/assets/app.js) and only be absolute if the parameter absolute is set to true.

Solution

Remove the call to URL::prependSiteUrl in Statamic\Addons\Theme\ThemeTags::themeUrl().

Environment details (please complete the following information):

  • Statamic Version 2.11.5

wanze avatar Nov 19 '19 19:11 wanze

It only appends the site_url as defined in your system locales setting. Do you have the full domain in there?

jackmcdade avatar Jan 09 '20 23:01 jackmcdade

Hi @jackmcdade

Yep, I have the full domain in there. I assumed that this would be the expected setup because the docs about localization use full urls: https://docs.statamic.com/localization#locales

Can I use relative urls as well?

Cheers

wanze avatar Jan 21 '20 08:01 wanze