Home » Php » How to pass variable from block to phtml in magento

How to pass variable from block to phtml in magento

Posted by: admin July 12, 2020 Leave a comment


I want to pass value from block but I am unable to get the desire results.
Something going wrong which I don’t know why.
I try the code "block type="multibanners/multibanners" name="multibanners" category_id="5" alias="multibanners" in xml file.
To get results I used echo $this->getCategoryId() and getData('category_id').
I search but all time the same code.
Can anyone help me whats wrong with the code.


How to&Answers:

You can set your variables like this:

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

and retreive it like this:



Mage_Core_Block_Template::assign() is made for that

Example of use in Mage_Page_Block_Html_Breadcrumbs::_toHtml() + direct call of $crumbs var in the breadcrumbs.phtml template file


Or in your controller, after


but before


use this code: