如何检查我们是否在购物车页面Shopify

时间:2015-03-17 04:13:25

标签: shopify

如何检查当前页面是否为theme.liquid中的购物车页面?我试过了page.handle=='cart',但它没有用。

5 个答案:

答案 0 :(得分:9)

您不需要handle过滤器,只需使用:

{% if template == 'cart' %}
  ...
{% endif %}

答案 1 :(得分:2)

这两个答案都不是绝对正确的,包括已接受的答案。

购物车模板可能与其他模板有替代,例如cart.fancy.liquid,可通过/cart?view=fancy访问。在这种情况下,相等运算符将无法按预期工作,因为template变量将等于cart.fancy

contains运算符也不是最佳选择,因为对于product.cartridge.liquid和类似模板来说,它也是 TRUE

基于上述内容,这是在主题中使用的更好的解决方案:

{%- assign templateBase = template | slice: 0, 4 -%}
{%- if templateBase == 'cart' -%}
  ...
{%- endif -%}
  • 购物车模板及其所有备用视图将为 TRUE
  • 对于任何可能包含以下内容的非购物车模板,其将为错误 cart的后缀顺序,即备用视图。

答案 2 :(得分:0)

我找到了解决方案。

使用{{template|handle}}

所以我的代码是

{% capture template_handle %}{{ template | handle }}{% endcapture %}

{% if template_handle == 'cart' %}

{% endif %}

答案 3 :(得分:0)

我们还可以使用:

android:windowSoftInputMode="adjustResize"

答案 4 :(得分:0)

这是另一种选择:

{% if request.path == routes.cart_url %}
  We are on the cart page.
{% else %}
  We are on some other page.
{% endif %}