Search code examples
asp.netshopifysectionsshopify-templatecustom-sections

Shopify Request to change section depending on the language's user


I hope you are doing well. I am working on my Shopify store and I am using a product description through a section that I have created and added to the product.liquid. I am trying to modify the description depending on the language the client is using so it shows the description in a different language.

Here is the code I am using:

    {% if request.host   contains 'storename.com/es' %}
<div class="tienda-questions">
<div class="tienda-questions-product">
...
</div>
</div>

{% endif %}

So the tricky part comes when I use the {% if request.host contains 'storename.com/es' %} When I use the same code based on the product.title the code seems to work perfectly showing the other description in a different language, by using {% if product.title == "product name" %}

I was wondering if anybody has experience with this and knows what request or value could I use to get it right and modify my section according to language.

Thank you for the help in advance!


Solution

  • You can use {{ request.host }} and {{ request.path }} to get full page url, and then usign conditional statement set specific code

    {% capture pageUrl %}{{ request.host }}{{ request.path }}{% endcapture %}
    {% if pageUrl contains 'storename.com/es' %}
       <div class="tienda-questions">
       <div class="tienda-questions-product">
       ...
       </div>
       </div>
    
    {% endif %}
    

    Also to get customer locale, you can try to get by using {{ request.locale.name }}