23

In Liquid, how can I find out all the values that a collection contains? Is there a print_r function or similar?

The example below will return the item title, but I would like to know what other variables item also holds.

item.title

Thanks.

Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270
addedlovely
  • 3,076
  • 3
  • 22
  • 37
  • I've no experience with liquid per se, which is why I can't post this as an answer, but you can use `inspect` in Ruby to print the contents of an object: http://apidock.com/ruby/Object/inspect . – polarblau May 30 '11 at 12:52
  • Thanks for the tip, but it doesn't work. – addedlovely May 30 '11 at 13:04

1 Answers1

42

Ah got there in the end! Not quite a print_r, but near enough to see whats available. This prints out the properties in JSON format, so you can see whats in there.

{{item | json}}
addedlovely
  • 3,076
  • 3
  • 22
  • 37
  • 4
    Note that not all available Liquid attributes will get dumped with the ` | json` filter - the structure of the objects may be different in some cases! Shopify's [Liquid reference](https://help.shopify.com/themes/liquid/objects) is a great resource should anything not quite behave the way you expect (or if you're looking for something that should be there but doesn't seem to be) – Dave B Apr 10 '17 at 17:55
  • Important point by Dave. For example a Shopify image might show as just the URL in the JSON, but in reality it's a Shopify object that includes properties like `.src`, and `.alt` – Chris Hayes Oct 26 '21 at 16:30