创建 cms 块并在 phtml 中调用

Creating cms block and calling in phtml

我刚从 magento 管理面板创建了一个 cms 块,现在我想把它放到 phtml 中,我试过这种方式:

<?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();
}
?>

我正在获取 cms 块,但如果语句不起作用,我该如何让它起作用?

如果您从管理面板创建了名为 ostore_footerb1-it 的 CMS 块。 然后下面将是在 .phtml

中调用它们的代码
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('ostore_footerb1-it')->toHtml(); 
?> 

另一种方法是:

布局中(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>

在您的 phtml 模板中:

<?php echo $this->getChildHtml('ostore_footerb1-it'); ?>

获取 phtml 文件中的静态块

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

试试这个:

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

或者这样:

将此作品添加到布局中:

<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>

并调用 phtml

 <?php echo $this->getChildHtml('ostore_footerb1-it'); ?>