shopfiy 二次开发之条件判断

网站中有好多这样的场景:

  1. 某个产品页面仅加载当前产品页的 css 或是 js
  2. 当前产品页对应的菜单再次点击时不跳转
  3. 判断当前模板中是否有某个字符串

 

// 判断当前模板中是否包含 product.SmartLock-UL3BT 的字符串,如果是 ,加载 ul3bt.scss.css
    {% if template contains  'product.SmartLock-UL3BT' %}
    {{ 'ul3bt.scss.css' | asset_url | stylesheet_tag }}
    {% endif %}
    {% if template contains  'product.SmartLock-U-Bolt-Pro' %}
    {{ 'u-bolt-pro.scss.css' | asset_url | stylesheet_tag }}
    {% endif %}
          // 判断当前模板,如果不等于指定字符串,则跳转到当前指定链接,否则 不跳转 #
<div class="product"> <a class="active" href="{% if template != 'product.SmartLock-U-Bolt' %}/products/ultraloq-u-bolt-bluetooth-enabled-and-keypad-smart-deadbolt{% else %} # {% endif %}"> <img src="//cdn.shopify.com/s/files/1/0795/7689/t/16/assets/ubolt-menu04.png?16736" /> <h4 class="pro-title">U-Bolt</h4> </a> <a class="active" href="{% if template != 'product.SmartLock-U-Bolt-Pro' %}/products/ultraloq-u-bolt-pro-bluetooth-enabled-fingerprint-and-keypad-smart-deadbolt{% else %} # {% endif %}"> <img src="https://www.u-tec.com/images/nav/uboltpro-menu04.png" /> <h4 class="pro-title">U-Bolt Pro</h4> </a> </div>

 

posted @ 2020-12-30 17:29  礼拜16  阅读(246)  评论(0编辑  收藏  举报