Nested loop not working for products

Topic summary

A developer is encountering issues with nested Liquid loops when attempting to retrieve the latest 4 product images from multiple collections in Shopify.

Problem:

  • The outer loop iterates through collections and assigns each collection’s handle to a variable
  • The inner loop should fetch products from each collection, but isn’t functioning correctly with the collection name/handle

Attempted Solution:
Another user (pawankumar) provided code suggestions, but the responses appear corrupted or improperly formatted, making them difficult to read. The original poster requested the code be reposted for clarity.

Current Status:
The issue remains unresolved. The discussion is ongoing, awaiting a properly formatted code solution that correctly references collections by their handle within the nested loop structure.

Summarized with AI on November 23. AI used: claude-sonnet-4-5-20250929.

Hi,

I am trying to get latest 4 product images from collections. Trying given code but loop is not working with collection name. Can you help to resolve this.


  {% for collection in collections %}
    - {% assign collectionHandle = collection.handle %}	
  		{{collectionHandle}}
		
  		{% for product in collections.collectionHandle.products limit: 4 %}  
		
- {{collectionHandle}}
			
				
			
		
		{% endfor %}
      
    
  {% endfor %}

Please try this
Thanks!

Hi @pawankumar

Can’t see your code. Can you post again.

Thanks
Con


  {% for collection in collections %}
    - {% assign collectionHandle = collection.handle %}	
  		{{collectionHandle}}
		
  		{% for product in collections[collectionHandle].products limit: 4 %}  
		
- {{collectionHandle}}
			
				
			
		
		{% endfor %}
      
    
  {% endfor %}

Please try this