必须以不同的方式调用 Cms 块来回显其内容。
在 breadcrumbs.phtml 下面的所有页面上呈现块:
app\design\frontend\base\default\layout\page.xml
在面包屑后添加:
在 Layout.xml 中
<block type="cms/block" name="block_name">
<action method="setBlockId"><block_id>my-block</block_id></action>
</block>
然后你必须在 3columns.phtml 中回显它:
<?php echo $this->getChildHtml('my-block') ?>
可能更容易在每页的基础上进行。
打开模板提示,找到一个你想附加你的 cms 内容的块,并在其中放置以下内容:
在模板文件中:
// Insert the block into the page.
$sBlockId = 'my-block';
$oBlock = Mage::getModel( 'cms/block' );
$oBlock->setStoreId( Mage::app()->getStore()->getId() );
$oBlock->load( $sBlockId, 'identifier' );
$oCmsHelper = Mage::helper( 'cms' );
$oProcessor = $oCmsHelper->getPageTemplateProcessor();
$sHtml = $oProcessor->filter( $oBlock->getContent() );
echo $sHtml;
或者:
echo Mage::app()->getLayout()->createBlock( 'cms/block' )->setBlockId( 'my-block' )->toHtml();
理想情况下,您可能希望创建一个模板,然后通过 layout.xml 附加并在该模板内回显您的 cms 块。
创建一个模板,在任何你想要的地方呈现你的 cms 块:
app\etc\modules\Spirit_Cms.xml
<?xml version="1.0"?>
<config>
<modules>
<Spirit_Cms>
<active>true</active>
<codePool>local</codePool>
</Spirit_Cms>
</modules>
</config>
app\code\local\Spirit\Cms\etc\config.xml
<?xml version="1.0"?>
<config>
<modules>
<Spirit_Cms>
<version>0.0.1</version>
</Spirit_Cms>
</modules>
<frontend>
<layout>
<updates>
<spirit_cms>
<file>custom.xml</file>
</spirit_cms>
</updates>
</layout>
</frontend>
</config>
app\design\frontend\rwd\default\layout\custom.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="content">
<block type="core/template" name="custom" template="custom.phtml" output="toHtml" />
</reference>
</default>
</layout>
app\design\frontend\rwd\default\template\custom.phtml
<?php echo Mage::app()->getLayout()->createBlock( 'cms/block' )->setBlockId( 'custom' )->toHtml(); ?>
在指定位置添加内容更灵活/更简洁。