handle missing from line_item object in liquid

timd_mackey
Shopify Partner
49 1 18

For some reason, the handle attribute seems to be missing from the line_item object when referencing a line item from the cart object. If I run this liquid code on the cart page:

{% for item in cart.items %}
  <p>Handle: {{ item.handle }}</p>
  <p>{{ item | json }}</p>
{% endfor %}

The item object will show the handle as an attribute when you dump it to json, but when referencing the handle directly, it will come up blank. Is there another reference for the handle that I should know, or is this just a bug?

0 Likes
timd_mackey
Shopify Partner
49 1 18

For anyone looking for the solution to this, you can get the product handle by referencing the line item's product, and then grabbing the handle from that. Like so:

{% for item in cart.items %}
  {{ item.product.handle }}
{% endfor %}

I don't understand why the handle is there on the line_item json object but is inaccessible, but anyhow here's the solution.

chippleh1392
New Member
1 0 0

3 years later, your post has saved me! It's bizarre how in the console, it displays as cart.items[0].handle, but you actually have to do cart.items[0].product.handle to access the handle string. 

0 Likes