mockie mockie - 2 months ago 17
PHP Question

Understanding Magento tag block type="catalog/product_list" name="home.catalog.product.list"

The code I mean is :

{{block type="catalog/product_list" name="home.catalog.product.list" alias="products_homepage" template="catalog/product/list.phtml"}}

Do you have a link where I can learn about it? I want to know if there another attribute. I'm trying to show products based on category, is it possible with kind of this code?


The code snippet that your referencing here is a widget that using in magento.

What is widget ?

If you are familiar with wordpress widgets, you may have an idea about what is widgets. According to me, Widgets are mainly designed for non-technial people who works with magento. By simply putting widgets, they can do some awesome works in magento. Magento has some default widgets availble with it and if you need you can develop widgets. Its just like a frontend extension development.

Theory For Widget that in Question

{{block type="catalog/product_list" name="home.catalog.product.list" alias="products_homepage" template="catalog/product/list.phtml"}}

This is our widget. As it's name suggest, it is a product list widget that is used to show some list of products in frontend. Wait a second... Then what is this code do then ?

<block type="catalog/product_list" name="home.catalog.product.list" alias="products_homepage" template="catalog/product/list.phtml" />

Now this is not a widget. This is a block which will use in Magento layouts to include product list based on some condition. That some condition will vary according to our need. Mean when it appears inside a category layout section, it will use to show products that are belong to a particular category. Now suppose, if you need to show some products based on some other conditions, then there too you need to use this block to list those products. The main thing you need to understand here is, you may need to do a lot of thing in order to to make this block show "something" in frontend.

But in case of widgets, we can skip this, by simply putting this code inside CMS->Pages. Magento will automatically render that block widget for you. So simple huh ? That is the power of widgets :)

What is this widget actually ?: This is infact a block that will use to show product list in frontend. Since it is a widget, it has some additional power than a normal block. One of that additional power is, widgets are automatically rendering one, while block may or may not be get automatically rendered. The above block and widget represents the block Mage_Catalog_Product_List. To trace the class that represent by this widget is pretty simple. It is based on the type that we specified. Here the type is catalog/product_list. catalog stands for Magento cor module Mage_Catalog and product_list is path to our block, this will turns to Block_Product_List. So when add on we get Mage_Catalog_Product_List. Now this block is used to show product lists in Magento. Each blocks in Magento do different kind of jobs.

Hope that makes sense. For more details on widget Go To This Link