Magento: Passing a value from a controller into the phtml

Another Magento quickie for when you want to pass a value into your phtml template file that is set/generated inside the controller.

Inside the controller you can do this:


Where $block could be something like

$block = $this->getLayout()->getBlock(“head”) ;

if you wanted to pass the value into the head template.

You can also set a value like this:


Then, inside the phtml template file you can get the value like this


Note you can pass multiple variables through a single $block->assign() like this


Facebook Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Apply your human brain cells and complete this highly complicated maths problem *