如何在液体中添加IF语句的活跃课程(shopify)

发布于 2025-02-07 17:18:13 字数 2000 浏览 1 评论 0原文

我在标题内有2个链接(一个链接将您带到一个商店,另一个链接将您带到另一家商店)。我需要在用户开设的商店中添加一个活动类(BMX商店& skate商店是需要添加活动类的两个类别的类)。因此,如果用户在BMX商店中,则该商店的链接变为大胆和下划线,反之亦然。

{% if request.url contains 'source-bmx-testing.myshopify.com' %}

{% elsif request.url contains 'sourceskate.myshopify.com' %}

{% endif %}

我知道该代码需要与上面的摘要相似,但不确定如何将其添加到代码中,我必须根据您的使用者将活动类添加到商店中。以下是我的代码:

            {%- for block in section.blocks -%}
              {%- case block.type -%}
              {%- when 'bmx-link' -%}
                <a class="link-container" href="{{ block.settings.store_link }}">
                  <div class="bmx-store">
                    <img 
                      width="15"
                      height="15"
                      src="{{ block.settings.icon_image | img_url: '15x15' }}"
                      srcset="{{ block.settings.icon_image | img_url: '15x15' }}"
                      alt="{{ block.settings.icon_image.alt }}">
                    <span>{{ block.settings.store_link_title }}</span>
                  </div>
                </a>
                {%- when 'skate-link' -%}
                  <a class="link-container" href="{{ block.settings.store_link }}">
                    <div class="skate-store">
                      <img 
                        width="15"
                        height="15"
                        src="{{ block.settings.icon_image | img_url: '15x15' }}"
                        srcset="{{ block.settings.icon_image | img_url: '15x15' }}"
                        alt="{{ block.settings.icon_image.alt }}">
                      <span>{{ block.settings.store_link_title }}</span>
                    </div>
                  </a>
              {%- endcase -%}
              {%- endfor -%}

I have 2 links inside the header (one link takes you to one stores the other link takes you to another store). I need to add an active class to the store the user is on (bmx-store & skate-store are the 2 classes that need active class adding to). So if the user is on the bmx store, the link for that store becomes bold and underlined and vice versa.

{% if request.url contains 'source-bmx-testing.myshopify.com' %}

{% elsif request.url contains 'sourceskate.myshopify.com' %}

{% endif %}

I know the code needs to be similar to the snippet above but not sure how to add it into the code i have to add the active class to the store depending on which one you are on. Below is my code:

            {%- for block in section.blocks -%}
              {%- case block.type -%}
              {%- when 'bmx-link' -%}
                <a class="link-container" href="{{ block.settings.store_link }}">
                  <div class="bmx-store">
                    <img 
                      width="15"
                      height="15"
                      src="{{ block.settings.icon_image | img_url: '15x15' }}"
                      srcset="{{ block.settings.icon_image | img_url: '15x15' }}"
                      alt="{{ block.settings.icon_image.alt }}">
                    <span>{{ block.settings.store_link_title }}</span>
                  </div>
                </a>
                {%- when 'skate-link' -%}
                  <a class="link-container" href="{{ block.settings.store_link }}">
                    <div class="skate-store">
                      <img 
                        width="15"
                        height="15"
                        src="{{ block.settings.icon_image | img_url: '15x15' }}"
                        srcset="{{ block.settings.icon_image | img_url: '15x15' }}"
                        alt="{{ block.settings.icon_image.alt }}">
                      <span>{{ block.settings.store_link_title }}</span>
                    </div>
                  </a>
              {%- endcase -%}
              {%- endfor -%}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过期以后 2025-02-14 17:18:13
          {% assign bmx_class = 'bmx-store' %}
          {% assign skate_class = 'skate-store' %}
          {% if shop.name == 'bmx' %} <!-- use youre store name here -->
               {% assign bmx_class = 'bmx-store current-store' %}
          {% elsif shop.name == 'skate' %}
               {% assign skate_class = 'skate-store current-store %}
          {% endif %}
          {%- for block in section.blocks -%}
          {%- case block.type -%}
          {%- when 'bmx-link' -%}
             {% assign class_block = bmx_class %}
          {%- when 'skate-link' -%}
             {% assign class_block = skate_class %}
          {% endcase %}
         
            <a class="link-container" href="{{ block.settings.store_link }}">
              <div class="{{ class_block }}">
                <img 
                  width="15"
                  height="15"
                  src="{{ block.settings.icon_image | img_url: '15x15' }}"
                  srcset="{{ block.settings.icon_image | img_url: '15x15' }}"
                  alt="{{ block.settings.icon_image.alt }}">
                <span>{{ block.settings.store_link_title }}</span>
              </div>
            </a>
          
          {%- endfor -%}

如果商店有2个以上的其他清洁液。

          {% assign bmx_class = 'bmx-store' %}
          {% assign skate_class = 'skate-store' %}
          {% if shop.name == 'bmx' %} <!-- use youre store name here -->
               {% assign bmx_class = 'bmx-store current-store' %}
          {% elsif shop.name == 'skate' %}
               {% assign skate_class = 'skate-store current-store %}
          {% endif %}
          {%- for block in section.blocks -%}
          {%- case block.type -%}
          {%- when 'bmx-link' -%}
             {% assign class_block = bmx_class %}
          {%- when 'skate-link' -%}
             {% assign class_block = skate_class %}
          {% endcase %}
         
            <a class="link-container" href="{{ block.settings.store_link }}">
              <div class="{{ class_block }}">
                <img 
                  width="15"
                  height="15"
                  src="{{ block.settings.icon_image | img_url: '15x15' }}"
                  srcset="{{ block.settings.icon_image | img_url: '15x15' }}"
                  alt="{{ block.settings.icon_image.alt }}">
                <span>{{ block.settings.store_link_title }}</span>
              </div>
            </a>
          
          {%- endfor -%}

If stores are more than 2 other cleaner solutions can be found.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文