How to pass a variable from a block to phtml in magento

I want to pass a value from a block, but I cannot get the results of a desire.
Something is wrong that I do not know why. I try the code "block type="multibanners/multibanners" name="multibanners" category_id="5" alias="multibanners" in the XML file.
To get the results, I used echo $this->getCategoryId() and getData('category_id') .
I am looking for the same code all the time.
Can someone help me with something wrong with the code.

Thanks.

+7
source share
3 answers

You can set such variables as follows:

 <block type="multibanners/multibanners" name="multibanners" alias="multibanners"> <action method="setData"><name>category_id</name><value>5</value></action> </block> 

and do it like this:

 $this->getCategoryId(); 
+9
source

Mage_Core_Block_Template::assign() for this

An example of using Mage_Page_Block_Html_Breadcrumbs::_toHtml() + a direct call to $crumbs var in the breadcrumbs.phtml template file

+3
source

Or in your controller, after

  $this->loadLayout(); 

but before

  $this->renderLayout(); 

use this code:

 $this->getLayout()->getBlock('multibanners')->setCategoryId(42); 
+1
source

All Articles