Magento: Add dynamic blocks in phtml files

Magento: Add dynamic blocks in phtml files
Magento: Add dynamic blocks in phtml files

To add dynamic blocks in phtml files. you can add this code to any where as you want in the phtml files like view.phtml:

<?php echo $this->getLayout()->createBlock('moduleName/blockType')->setTemplate('moduleName/templateName.phtml')->toHtml(); ?>
/*
- moduleName: your module's name (Ex: catalog)
- blockType: the path to block file (Ex: product_view ) (Catalog/Block/Product/View.php)
*/