Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
I recently added a second locale to my shop, for which I'm using the subfolder structure.
But now I'm struggling to come up with a clean implementation to make sure all my links include the subfolder in the final URL.
The first issue seems to routes.root_url returns / for the primary locale, and something like /nl for other locales. This means that you cannot just insert routes.root_url in your urls, but have to come up with some conditional logic (otherwise you will end up with double slashes for the primary domain). So my best attempt is currently:
relative base url:
{% if localization.language.primary == false %}{{ routes.root_url }}{% endif %}
absolute base url:
{{ shop.url }}{% if localization.language.primary == false %}{{ routes.root_url }}{% endif %}
This seems to work, but not very clean. I would suspect that Liquid would have better support for this. Am I missing an obvious variable?
And then the next issue is how I cleanly implement this throughout my application. I could ofcourse add the above code to all my links, but that feels very ugly.
I rather define a custom global variable, something like:
{% assign absoluteBaseUrl = {{ shop.url }}{% if localization.language.primary == false %}{{ routes.root_url }}{% endif %} %}
But I don't see a clean path forward in using absoluteBaseUrl throughout my files. I can't declare it in theme.liquid (because the variable is then only accessible in that file), so I would have to include this as a snippet in all my templates and pass the variable to all snippets which are includes using 'render'. Again; that feels far from clean.
Am I missing something? Any tips?
Hey Community! As we jump into 2025, we want to give a big shout-out to all of you wh...
By JasonH Jan 7, 2025Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024