2

I use the @web alias in the configuration of the base URLs of the sites (following Craft 3 documentation). The @web alias allows a shortcut to the URL of the folder that contains the index.php file loaded for the request.

However, when I loop through craft.app.sites.getAllSites using Twig, the value of baseUrl still prints @web in the URL, instead of transform it in its original URL.

As a workaround, I could get the original URL using {{ craft.app.sites.currentSite.baseUrl ~ site.uri | replace({ '@web': '' }) }}. But this seems a very dirty solution that will probably not always work.

2
  • The "Craft 3 documentation" link is no longer active. Jan 28 '20 at 4:21
  • 1
    Thank you @DavidRhoden, link updated. Jan 28 '20 at 9:29
4

So luckily for us, Brandon recently added the alias() Twig function. It should show up in Craft CMS 3 RC7. You can see the discussion about it here: https://github.com/craftcms/cms/issues/2327

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.