Pass a variable to a template .phtml block in Magento
Here’s a simple example to pass a variable from Magento (template, controller, etc) file to a block with php code.
Call a block using the createBlock() method:
[code language=”php”]
<?php
echo $this->getLayout()->createBlock(‘module/template_name’)
->setData(‘key’, ‘some value’)
->setTemplate(‘module/newblock.phtml’)->toHtml();
[/code]
The setData() method in the above code creates a variable, and you can access the variable with below code in the code that handles the block you created:
[code language=”php”]
<?php
echo $this->key;
[/code]
Search within Codexpedia
Custom Search
Search the entire web
Custom Search
Related Posts