If you've found this post by the power of Google it means that you're doing cool things with Shopify Liquid, but you've hit an error. Let's talk quickly about the limit.
There is a limit of 20 unique handles with all_products on a page. As long as you're not pushing any more than 20 you'll never see the error.
The common place I see the Exceeded maximum number of unique handles for all_products error is on related product scripts where theme developers try and loop over every collection, and every product within that. Within those loops sits the all_products tag, getting called every single time. It's pretty easy to hit that 20 limit when you're using it 100s (if note 1000s of time on the one page).
There's no work around here so be sure to design your code around this limit.