Lemonstand simple display product list from category

November 20, 2012

I quite often get asked how to achieve this easily by friends and colleagues and in there defence it's not 'clearly' documented. So I thought i'd knock something up really quickly to show you how it can be done.

In this example I create a category called 'Featured' and I importantly set the 'API code' for this category to 'featured'. This is found at the very bottom of the category creation / edit page.

I want to pull in some featured products into my homepage so I dive into the CMS and pull up the homepage.

You'll want to enter the below snippet into the template.

$this->render_partial('shop:product_list', array(
)) ?>

This snippet first fetches the correct category object and then renders a partial called shop:product_list (or shop;product_list.htm if you use template based files) with all of the products under this category.

Now you just need to make your partial and add some basic code to it.

I'm not going to dive into the full extent of what you can now do with the below code but just get you on your way.

In your shop:product_list partial add the following code:

And that's all there is to it. You'll now be getting a list of all the products in this category on your homepage. Of course it is also worth noting you could use this same partial in many places across your site. It's use will probably largely depend on how heavily uniform or customised the section on your site is.

Hope this is of some use.

About me

Hello! I'm David Heward, how are you going? I'm a Senior Devops/Build Engineer, specialising in AWS & Cloud Automation. Based in London. Strong 10+ year background in Software development. Have a read of my blog. Have a look at some of my working projects. Contact me at @davehewy or on Linkedin.