Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if we are in cart page Shopify

Tags:

shopify

How can I check if the current page is the cart page in theme.liquid? I tried page.handle=='cart' but it is not working.

like image 431
user1917451 Avatar asked Mar 17 '15 04:03

user1917451


People also ask

How do I get to cart page on Shopify?

Click on your online store. Under Shopify themes settings, select your theme, then click on UPDATE CART.

How do I Preview checkout on Shopify?

to checkout in preview URL do below steps: OPen Shopify Admin -> Click on the theme 'Action' button which you want to check preview -> Click on 'Preview' in the same browser in which you have opened the Shopify backend. Now proceed with the checkout. It's allows you to do checkout in the preview theme.

What is cart page on Shopify?

The cart page shows a summary of all of the products that a customer has added to the cart, a subtotal and a total price for the order, and a Checkout button that directs customers to Shopify's secure checkout pages.


2 Answers

You don't need the handle filter, you can just use:

{% if template == 'cart' %}
  ...
{% endif %}
like image 128
Steph Sharp Avatar answered Oct 15 '22 18:10

Steph Sharp


Neither answer is absolutely correct, including the accepted one.

The cart template as others may have alternates e.g. cart.fancy.liquid which can be accessed via /cart?view=fancy. In that case, the equality operator will not work as expected as template variable will be equal to cart.fancy.

The contains operator is not the best option as well, as it will also be TRUE for product.cartridge.liquid and similar templates.

Based on the above here's the better solution to use in your themes:

{%- assign templateBase = template | slice: 0, 4 -%}
{%- if templateBase == 'cart' -%}
  ...
{%- endif -%}
  • It will be TRUE for cart template and all its alternate views.
  • It will be FALSE for any non-cart templates that may contain cart sequence in their suffixes i.e. alternate views.
like image 44
Vladimir Avatar answered Oct 15 '22 20:10

Vladimir