在 magento 页面的内容之前添加块
Add block before content in magento page
我需要在其中一个页面的面包屑之后添加一个块,my-page
我尝试在管理员中创建一个名为 my-block
的块,并在 frontend/theme/default/template/page/2columns-left.phtml
中添加 <?php echo $this->getChildHtml('my-block') ?>
,但它没有显示块 my-block
的内容。
我也加了
<page-name>
<reference name="root">
<block type="core/template" name="my-block" as="my-block" before="content" after="breadcrumbs" template="page/html/my-block.phtml"/>
</reference>
</page-name>
在 local.xml 文件中,但我不确定是否真的有必要。
我是不是漏掉了什么?
谢谢
必须以不同的方式调用 Cms 块以呼应其内容。
要在以下所有页面上呈现块 breadcrumbs.phtml:
app\design\frontend\base\default\layout\page.xml
在面包屑之后添加:
In 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 内容附加到的块并将以下内容放入其中:
In template file:
// 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;
OR:
echo Mage::app()->getLayout()->createBlock( 'cms/block' )->setBlockId( 'my-block' )->toHtml();
理想情况下,您可能希望创建一个模板,然后通过 layout.xml 附加该模板,并在该模板内回应我们的 cms 块。
Creating a template that renders your cms block wherever you desire:
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(); ?>
更多 flexibility/less 混乱在指定位置添加内容。
我需要在其中一个页面的面包屑之后添加一个块,my-page
我尝试在管理员中创建一个名为 my-block
的块,并在 frontend/theme/default/template/page/2columns-left.phtml
中添加 <?php echo $this->getChildHtml('my-block') ?>
,但它没有显示块 my-block
的内容。
我也加了
<page-name>
<reference name="root">
<block type="core/template" name="my-block" as="my-block" before="content" after="breadcrumbs" template="page/html/my-block.phtml"/>
</reference>
</page-name>
在 local.xml 文件中,但我不确定是否真的有必要。
我是不是漏掉了什么?
谢谢
必须以不同的方式调用 Cms 块以呼应其内容。
要在以下所有页面上呈现块 breadcrumbs.phtml:
app\design\frontend\base\default\layout\page.xml
在面包屑之后添加:
In 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 内容附加到的块并将以下内容放入其中:
In template file:
// 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;
OR:
echo Mage::app()->getLayout()->createBlock( 'cms/block' )->setBlockId( 'my-block' )->toHtml();
理想情况下,您可能希望创建一个模板,然后通过 layout.xml 附加该模板,并在该模板内回应我们的 cms 块。
Creating a template that renders your cms block wherever you desire:
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(); ?>
更多 flexibility/less 混乱在指定位置添加内容。