简体   繁体   中英

Shopify If statement not working correctly

I'm creating a new shopify theme. I've an option in themes options panel which let user select a category from drop down. And I've some code which i don't want to be executed if no category is selected from that drop down.

The code i've written is like this:

{% if settings.product_rightbar != "" %}
    This code shouldn't be displayed if no catoegory is selected
{% endif %}

Problem is on fresh theme install, the drop down shows text 'Select a collection' if the user doesn't select any category, the above if statement still allows code to execute the inner code. However, if the user selects a category from drop down, and then removes it, the drop down shows text 'None' in that case the above if statement still blocks the execution the inner code, as it is supposed to do. See image below. 在此处输入图片说明

We want to resolve this scenerio, that the code within if statement shouldn't display on fresh theme install as well, when the drop down is showing 'Select a collection'

Their was a default value set for product_rightbar in settings_data.json file. I just make the default value empty string, and it worked. Took me 2 days to figure out this simple problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM