handle missing from line_item object in liquid

Highlighted
Shopify Partner
28 0 9

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
Shopify Partner
28 0 9

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.

0 Likes