How do I get all products of a store and assign it to a variable?

How do I get all products of a store and assign it to a variable?

vaibhavmundra
Shopify Partner
2 0 0

I'm trying 

{% for unique_prod in all_products %}
<p>{{unique_prod.title}}</p>
{% endfor %}
 
But it's printing nothing. Probably because all_products is an object. How do I get all the products of the store (I guess 20 is the limit per page)? Is there something I'm doing wrong?
Reply 1 (1)

Jason
Shopify Partner
11206 226 2313

all_products does have a limit of 20 unique handles per page. In this case you're not using it properly as it doesn't return a data set of products like that, but instead returns 1 product based on the handle you feed it.

 

eg:

 

{{ all_products['some-handle'].title }}

 

More info in the docs:
https://shopify.dev/api/liquid/objects#all_products

 

It's possible you would want to loop over a collection instead. Still keep in mind that looping over massive amounts of products can lead to performance issues so you can often be better off pulling that data in async.

 

★ I jump on these forums in my free time to help and share some insights. Not looking to be hired, and not looking for work. http://freakdesign.com.au ★