我刚刚从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阻止,但如果声明无效,我该如何才能使其正常工作?
答案 0 :(得分:1)
如果您已从管理面板创建名为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'); ?>
答案 1 :(得分:0)
在phtml
文件中获取静态块
echo $this->getLayout()->createBlock('cms/block')->setBlockId('block_identifier')->toHtml();
答案 2 :(得分:0)
试试这个:
<?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'); ?>