新闻中心

如何调用Magento的静态块

作者 / 无忧主机 时间 2015-02-04 17:06:34

在无忧主机php空间中这里也有很多站长朋友使用Magento程序,但是有一位站长找到小编询问调用静态块的问题,因小编也不懂程序,所以当时无法帮助那位站长。既然有问题,小编就想尽力帮忙站长朋友进行处理。通过四处寻找资料,无忧主机小编总结出几种不同的调用方法,也只能算是给这类问题做了一个归类,有兴趣的站长朋友们可以参考一下。 首先要在后台创建一个order_form静态块 Block Title:Order Form Identifier:order_form Status:Enabled Content:自定义内容 1、在.phtml文件中直接调用此静态块方法如下:

<?php 
$block = Mage::getModel('cms/block') 
->setStoreId(Mage::app()->getStore()->getId()) 
->load('order_form'); 
$content = $block->getContent(); // Block的原始内容已经获得 
$processor = Mage::getModel('core/email_template_filter'); 
echo $html = $processor->filter($content); 
?>
上面的代码是比较长的,下面还有个较短的一个代码,都是可行的
<?php echo $this->getLayout()->createBlock(‘cms/block’)->setBlockId('order_form')->toHtml() ?>
2、在CMS页面的Content中调用此静态块方法如下:
{{block type="cms/block" name="cms_test_block" block_id="order_form" }}
只需要将里面“order_form”改成你的静态块对应的“block_id”即可 3、在layout中调用此静态块方法如下:
<reference name="footer"> 
<block type="cms/block" name="order_form" before="-"> 
<action method="setBlockId"><block_id>order_form</block_id></action> 
</block> 
</reference>
希望这些方法能帮助到使用Magento程序去调用静态块,让大家更好的灵活运用。 无忧主机相关文章推荐阅读: MAGENTO文件模板介绍 开发MAGENTO模板先知道 MAGENTO重装如何恢复网站教程 MAGENTO搬家报错之一解决方法

本文地址:https://www.51php.com/magento/18575.html

1
1
1
1
1
1
1

客户服务热线

0791-8623-3537

在线客服