2

I just created a cms block from magento admin panel and now I want to get it into the phtml I tried this way:

<?php 
$currentview =  Mage::app()->getStore()->getCode();

if($currentview = 'default'){
echo $this->getLayout()->createBlock('cms/block')->setBlockId('ostore_footerb1')->toHtml();
}
else if($currentview = 'it'){ 
echo $this->getLayout()->createBlock('cms/block')->setBlockId('ostore_footerb1-it')->toHtml();
}
?>

I am getting cms block but if statement not working how can I make it working ?

MZ Game
  • 55
  • 1
  • 10
  • 2
    I take you have 'echo' before the above? are you sure your editing the correct template file - try putting

    HELLO

    in there - does that appear? have you flushed all the caches after making the changes ?
    – PixieMedia Jul 09 '15 at 11:43
  • yes I am sure. Oh I just notice actually I am trying condition using php in the phtml but its not working. how can I use if condition in phtml – MZ Game Jul 09 '15 at 12:32
  • $currentview = 'default' change to $currentview == 'default' – Oscprofessionals Jul 09 '15 at 19:26

3 Answers3

1

If you have created CMS block named ostore_footerb1-it from admin panel. Then following will be code to call them in .phtml

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('ostore_footerb1-it')->toHtml(); 
?> 

Another way to do this is :

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_ostore_footerb1-it" as="cms_newest_product">
                <action method="setBlockId"><block_id>ostore_footerb1-it</block_id></action>
            </block>
        </reference>
    </cms_page>
</default>

In your phtml template:

<?php echo $this->getChildHtml('ostore_footerb1-it'); ?>
Manashvi Birla
  • 2,837
  • 3
  • 14
  • 28
0

To get static block in phtml file

echo $this->getLayout()->createBlock('cms/block')->setBlockId('block_identifier')->toHtml();
MeenakshiSundaram R
  • 2,837
  • 3
  • 29
  • 41
0

Try this:

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('ostore_footerb1-it')->toHtml(); ?>

Or this:

add this piece to the layout:

<default>
    <cms_page> <!-- need to be redefined for your needs -->
        <reference name="content">
            <block type="cms/block" name="ostore_footerb1-it" as="ostore_footerb1-it">
                <action method="setBlockId"><block_id>ostore_footerb1-it</block_id></action>
            </block>
        </reference>
    </cms_page>
</default>

and call in phtml

 <?php echo $this->getChildHtml('ostore_footerb1-it'); ?>
Mageworx
  • 932
  • 4
  • 7