Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more
My store has two languages, so I have to add a language switcher. I wanted the user to be able to change the language without leaving the current page. So for this I haven't found a better way than just adding it via "if page type".
{% for link in linklists[settings.linklist_language].links %} {% if link.title == localization.language.name %} {% elsif link.title == 'Lang1' and localization.language.name == "Lang1" %} {% elsif link.title == 'Lang2' and localization.language.name == "Lang2" %} {% else %} {% if request.page_type == "collection" %} <li><a href="{{ link.url }}/collections/{{ handle }}">{{ link.title }}</a></li> {% elsif request.page_type == "product" %} <li><a href="{{ link.url }}/products/{{ handle }}">{{ link.title }}</a></li> {% elsif request.page_type == "blog" %} <li><a href="{{ link.url }}/blogs/{{ handle }}">{{ link.title }}</a></li> {% elsif request.page_type == "article" %} <li><a href="{{ link.url }}/blogs/{{ blog.handle }}/{{ handle }}">{{ link.title }}</a></li> {% elsif request.page_type == "page" %} <li><a href="{{ link.url }}/pages/{{ handle }}">{{ link.title }}</a></li> {% elsif request.page_type == "cart" %} <li><a href="{{ link.url }}/cart">{{ link.title }}</a></li> {% elsif request.page_type == "policy" %} <li><a href="{{ link.url }}{{ policy.url }}">{{ link.title }}</a></li> <!-- Don't work, policy.url is empty --> {% else %} <li><a href="{{ link.url }}">{{ link.title }}</a></li> {% endif %} {% endif %} {% endfor %}
This method worked on different types of pages, but it doesn't work on my "/policies/terms-of-service" because {{ policy.url }}" is empty.