Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to call static & custom block directly from phtml file ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 672
    Comment on it

    In magento, sometimes you need to call block in magento phtml to get the content of block. Here is an easy way to call static block & custom block in any template file.


    1. Call Static block content in magento phtml file.

     

    You can easily call any static block in magento template file. At first, you have to create a static block in admin panel.
    then, you can call the static block in any phtml file with the help of following code:

     

    echo $this->getLayout()
              ->createBlock('cms/block')
              ->setBlockId('your-block-identifier')
              ->toHtml();

     

    2. Call custom block method of custom module in magento phtml file.

     

    To do this, create object for block in template file.

     

    $block = Mage::app()->getLayout()->getBlockSingleton('modulename/blockclassname');

     

    $block is object of class 'blockclassname'. Now you can call any method of this class using $block.
    I have assumed my blockclassname.php has GetXYZ() method.

     

    echo $block->getXYZ();

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: