Magento CMS Static Block

magento 后台添加了一个cms static block

114137_cMva_2715471.png

一、在.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,如

174106_hI7I_2715471.png

访问路径: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');

转载于:https://my.oschina.net/ganfanghua/blog/1486801

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值