magento 后台添加了一个cms static block
一、在.phtml 文件,调用该静态块
1:单纯输出静态块的内容,<img src="{{media url="wysiwyg/design/opentao.png"}}" />这种内容不会解析的。
<?php
//get static block content
$storeId = empty(Mage::app()->getStore()->getId()) ? 1 : Mage::app()->getStore()->getId(); //storeId=1 : english
$blockId = 'foot_guarantee_' . $storeId;
$blockContent = Mage::getModel('cms/block')->setStoreId($storeId)->load($blockId)->getContent();
var_dump($blockContent);
?>
2:在.phtml页面,解析静态块内容被按html格式输出,则:上述图片可以解析出来。
<?php //get static block content $blockId = 'foot_guarantee_1'; echo $this->getLayout()->createBlock(‘cms/block’)->setBlockId($blockId)->toHtml() ?>
二、在CMS Page页面
1:在cms page Content中调用static block
{{block type="cms/block" block_id="foot_guarantee_1" template="cms/content.phtml"}}
2:在cms page Content中调用other block
{{block type="searchautocomplete/form" name="top.search" as="topSearch" template="search/default.phtml"}}
3:前台访问cms page,如
访问路径:http://gfh.shared.zenote.ot.trd/why
三、在layout中调用静态块
首先先设置block相应的xml内容:
<reference name=”footer”>
<block type=”cms/block” name=”foot_guarantee_1” before=”-”>
<action method=”setBlockId”><block_id>foot_guarantee_1</block_id></action>
</block>
</reference>
然后在相应在模板文件.phtml中调用
getChildHtml('foot_guarantee_1');