Skip to content

Instantly share code, notes, and snippets.

@evgv
Last active March 14, 2017 10:36
Show Gist options
  • Save evgv/e9d2c8e331bf99dbc50195a87020d970 to your computer and use it in GitHub Desktop.
Save evgv/e9d2c8e331bf99dbc50195a87020d970 to your computer and use it in GitHub Desktop.
Magento. Create block.
    /**
     * First way (1) use layout for block create
     */
    $block = Mage::app()->getLayout()->createBlock('customermenu/page_html_header_menu')
                                     ->setTemplate('customermenu/page/html/header/menu.phtml')
                                     ->toHtml();
                                     
    /**
     * First way (2) use layout for block create
     * Need setTemplate() in block __construct()
     */
    $block = Mage::app()->getLayout()->createBlock('customermenu/page_html_header_menu')
                                     ->toHtml();


    /**
     * Second way use core method getBlockSingleton()
     * Need setTemplate() in block __construct()
     */
    $block = Mage::getBlockSingleton('customermenu/page_html_header_menu')
                    ->toHtml();

    /**
     * Second way use core method getBlockSingleton() with setTemplate()
     */
    $block = Mage::getBlockSingleton('customermenu/page_html_header_menu')
                    ->setTemplate('customermenu/page/html/header/menu.phtml')
                    ->toHtml();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment