Sunday 26 October 2014

Call / Get static block as html in a phtml file Magento

It regularly happens that Magento webshop administrators like to mention additional information on a product page. Think about upfront shipping information or extra service information to gain trust from the potential customer. Magento does not provide a default option for this. You could insert it within the product (short) description but then you should repeat/change this for every product. So, that's not a practical option.


You can add call it two way:

Option 1

In the layout (app/design/frontend/your_theme/layout/default.xml):
<default>
    <cms_page> <!-- need to be redefined for your needs -->
        <reference name="content">
            <block type="cms/block" name="cms_newest_product" as="cms_newest_product">
                <action method="setBlockId"><block_id>newest_product</block_id></action>
            </block>
        </reference>
    </cms_page>
</default>
In your phtml template:
<?php echo $this->getChildHtml('newest_product'); ?>




Option 2

Following code will work when you Call CMS-Static Block directly from .phtml file in Magento.
<?php echo 

$this->getLayout()->createBlock('cms/block')->setBlockId('block_identifier')->toHtml();

?>

 


No comments

Post a Comment

Fix The Magento. All rights reserved. ©