inside of List.php, the only code I can see that would retrieve this variable (category_id) is this:
if ($this->getCategoryId()) { $category = Mage::getModel('catalog/category')->load($this->getCategoryId()); $layer->setCurrentCategory($category); }
However, I cannot seem to replicate this:
//in layout update XML in admin section when editing Home Page within the CMS <block type="myCompany_Leftbar/Leftbar" category_id="3" template="leftbar/left.phtml" />
<?php /****************************** Leftbar.php *****************************/ class myCompany_Leftbar_Block_Leftbar extends Mage_Catalog_Block_Product_Abstract { public $catid;
As far as I know the setData method adds the data into the block not the model. Block data is accessible using $this in the phtml file (because the phtml file is using the block class ‘Mage_Catalog_Category’).
Doing it as a “category_id” attribute in the block only works in the “{{block}}” construct, where the email template filtering processes the attributes of the {{block ...}} So you can do this from email templates and on Cms pages (which use email templates too), but you can’t do anything analogous with straight “<block>” elements in layouts. For layouts, you have to use an action:
However, I should add I haven’t had a lot of success getting blocks from the Mage Catalog module to work independently of their usual context. You can define attributes using actions, but blocks defined in the Catalog module seem to depend on a lot of context that is set by the controllers of the Catalog module, and it is difficult to get them to work in other contexts just by setting some attributes, like category_id. For one thing, a lot of these blocks also set things with Mage::register.
So this is a reasonable method to pass parameters to simple blocks and custom blocks where you know exactly what has to be set, but it is a bit unpredictable with Mage Catalog blocks.
Doing it as a “category_id” attribute in the block only works in the “{{block}}” construct, where the email template filtering processes the attributes of the {{block ...}} So you can do this from email templates and on Cms pages (which use email templates too), but you can’t do anything analogous with straight “<block>” elements in layouts. For layouts, you have to use an action:
However, I should add I haven’t had a lot of success getting blocks from the Mage Catalog module to work independently of their usual context. You can define attributes using actions, but blocks defined in the Catalog module seem to depend on a lot of context that is set by the controllers of the Catalog module, and it is difficult to get them to work in other contexts just by setting some attributes, like category_id. For one thing, a lot of these blocks also set things with Mage::register.
So this is a reasonable method to pass parameters to simple blocks and custom blocks where you know exactly what has to be set, but it is a bit unpredictable with Mage Catalog blocks.