【问题标题】:Shopify Liquid: Using 'if' statements to hide element on different pagesShopify Liquid:使用“if”语句隐藏不同页面上的元素
【发布时间】:2015-12-12 05:43:25
【问题描述】:

我将此代码放入我的 collection.liquid 模板中,以便客户可以按产品类型进行选择。效果很好!

<ul class="types">
    {% for product_type in collection.all_types %}
		<li class="{{ product_type | handleize }}">{{ product_type | link_to_type }}</li>
	{% endfor %}
</ul>

但是,我希望能够在选择某些内容后“隐藏”此列表。这是因为客户选择了 T-Shirts 后,它会将他们带到 T-Shirts 页面,该页面顶部有一个巨大的“T-Shirts”标题,并且由于上面的代码,一个较小的“T-Shirts” “ 在它下面。拥有重复的页面标题很烦人,我一直无法弄清楚如何在选择产品类型后删除列表。我试过这个:

ul.nothing { display:none; }
<ul class="types" {% if page_title contains product_type %}class="nothing"{% endif %}>
    {% for product_type in collection.all_types %}
		<li class="{{ product_type | handleize }}">{{ product_type | link_to_type }}</li>
	{% endfor %}
</ul>

它不起作用,我想避免手动执行此操作

body#t-shirts ul.types { display:none; }

等等...适用于我所有不同的产品类型。

救命!

提前谢谢你!

【问题讨论】:

    标签: shopify liquid


    【解决方案1】:

    如果你改变它应该可以工作

    {% if page_title contains product_type %}
    

    {% if page_title == collection.current_type %} 
    

    【讨论】:

      【解决方案2】:
      <li> {% for collection in collections %}
           {% if collection.products_count != 0 %}
           <br><a  href="{{ collection.url }}"> {{ collection.title }} <span class="count">({{collection.products_count}})</span></a>
      {% endif%}  {% endfor %}  </li>
      

      【讨论】:

      • 这是我的修复方法,希望对您有帮助
      猜你喜欢
      • 2019-03-20
      • 2021-10-04
      • 1970-01-01
      • 2019-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多