Magento 创建cms块并调用phtml
我刚刚从magento管理面板创建了一个cms块,现在我想将其放入phtml,我尝试了以下方法:Magento 创建cms块并调用phtml,magento,magento-1.7,magento-1.8,magento-1.9,Magento,Magento 1.7,Magento 1.8,Magento 1.9,我刚刚从magento管理面板创建了一个cms块,现在我想将其放入phtml,我尝试了以下方法: <?php $currentview = Mage::app()->getStore()->getCode(); if($currentview = 'default'){ echo $this->getLayout()->createBlock('cms/block')->setBlockId('ostore_footerb1')->toHtml()
<?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\u footerb1-it
的cms块。
然后,下面是在.phtml中调用它们的代码
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('ostore_footerb1-it')->toHtml();
?>
另一种方法是:
在布局(app/design/frontend/your_theme/layout/default.xml)中:
ostore_-it
在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>
ostore_-it
并调用phtml
<?php echo $this->getChildHtml('ostore_footerb1-it'); ?>
我想您在上述内容之前是否有“echo”?你确定你正在编辑正确的模板文件吗?试着把HELLO放在那里-会出现吗?更改后是否刷新了所有缓存?是的,我确定。哦,我只是注意到实际上我正在尝试在phtml中使用php,但它不起作用。如何在phtml$currentview='default'中使用if条件更改为$currentview='default'实际上我想在phtml中使用if语句,但它不起作用。如何在phtml中使用if语句?我刚刚编辑了我的问题,我的问题中有代码。请检查您是否将single=放在if语句中,它应该包含==
<?php echo $this->getChildHtml('ostore_footerb1-it'); ?>