Magento在代码中调用静态块(Static Block)
文章分类:PHP 编程
假设有在Magento 后台建立一个Static Block 名字为'footer_links' ,在phtml (其他php 文件中方法一样)中调用方式如下:
- // Block 是与店铺相关的,所以要设置setStoreId.
- $block = Mage::getModel('cms/block')
- ->setStoreId(Mage::app()->getStore()->getId())
- ->load('footer_links');
- $content = $block->getContent(); // Block 的原始内容已经获得
- $processor = Mage::getModel('core/email_template_filter');
- $html = $processor->filter($content);
Mage::getModel('core/email_template_filter')->filter() 是必须的,因为Static Block 里可能包含Magento 的模板语言(如:{{store url=""}} ),fiter 将翻译成实际的值