我希望我的收藏夹排序选项仅显示以下内容:畅销,价格(从低到高),价格(从高到低),按字母顺序(A-Z),按字母顺序(Z-A)
当我添加以下代码时,它仅成功显示允许用户按价格(从高到低/从低到高)对产品进行排序的值
{% for option in collection.sort_options %}
{% if option.value contains 'price-' %}
<option value="?sort_by={{ option.value }}" {% if option.value == selected %}selected{% endif %}>
{{ option.name }}
</option>
{% endif %}
{% endfor %}
集合排序选项的for循环导致:
<select name="sort_by">
<option value="manual">Featured</option>
<option value="best-selling">Best selling</option>
<option value="title-ascending">Alphabetically, A-Z</option>
<option value="title-descending">Alphabetically, Z-A</option>
<option value="price-ascending">Price, low to high</option>
<option value="price-descending">Price, high to low</option>
<option value="created-ascending">Date, old to new</option>
<option value="created-descending">Date, new to old</option>
</select>
但是,我还想添加包含最佳或标题的值,但是当我替换
时{% if option.value contains 'price-' %}
使用
{% if option.value contains 'price-' or 'best-' %}
它只会显示所有值,而不仅仅是显示价格或最佳值。我该如何解决?
答案 0 :(得分:1)
您需要在or
运算符之后重复整个条件语句:
{% if option.value contains 'price-' or option.value contains 'best-' %}
...
{% endif %}