I'm working on a multi-site setup (for a localized website). In my .env
file, I have defined a SITE_BASE_URL
variable. Then, in the control panel, I set up each site's base url with that environment variable (e.g. http://$SITE_BASE_URL/en
, http://$SITE_BASE_URL/nl
, etc. for each language).
However, when I need to generate urls in my Twig templates, this environment variable doesn't seem to get parsed; I get generated html that looks like this <a href="http://$SITE_BASE_URL/en/services">...</a>
.
Example from a twig template:
{% set pages = [
craft.entries.section("services").one(),
craft.entries.section("products").one(),
] %}
{% for page in pages %}
<a href="{{ page.url }}">{{page.title}}</a>
{% endfor %}
This gives me URLs like http://$SITE_BASE_URL/en/services
, http://$SITE_BASE_URL/en/products
, etc.
This setup was working fine for me when using the @web
alias in the CP. Why doesn't it work with the env variable? The only reason I switched to env variables is that it is not recommended to use the @web
alias due to cache poisoning.
I've already looked at https://github.com/craftcms/cms/issues/3719 and baseUrl outputs environment variable
Neither have solved my issue...