【问题标题】:Tag filter into Shopify标记过滤器到 Shopify
【发布时间】:2021-09-29 05:48:07
【问题描述】:

我想根据前缀过滤标签。假设我的标签为 filter-material-woolen、filter-material-woolen1、filter-febric-velvet、filter-febric-velvet1。所以我必须过滤前缀为“filter-”的标签,中间关键字如“material,febric”将作为标题,最终键将作为值。

<h1>material</h1>
<p>woolen1,woolen</p>

<h1>febric</h1>
<p>velvet,velvet1</p>

【问题讨论】:

    标签: shopify shopify-app shopify-template


    【解决方案1】:
    <ul>
        {% for tag in collection.all_tags %}
            {% if tag contains 'filter-' %}
                <li>{{ tag | remove: 'filter-material-' | remove: 'filter-febric-' | link_to_tag: tag }}</li>
            {% endif %}
        {% endfor %}
    </ul>
    

    【讨论】:

    • 这将移除材料和织物。我想要材料和织物作为标题,然后是值。只需要删除过滤器前缀。将来,如果添加了任何动态键,如“filter-test-test1”,那么 test 的标题将类似于

      test

      ,然后值为 test1。基本上,我们需要按前缀过滤,然后按中间键分组并循环值(最后一个键)
    猜你喜欢
    • 2016-09-07
    • 1970-01-01
    • 2022-10-16
    • 1970-01-01
    • 2017-03-09
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多