在后台创建一个order_form静态块,内容分别如下:
Block Title: Order FormIdentifier: order_formStatus :EnabledContent :自定义内容
方法一:如果要在.phtml文件中直接调用这个静态块,那可以采用以下两种方法
1:
<?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);?>
Mage::getModel(‘core/email_template_filter’)->filter()是必须的,因为Static Block里可能包含Magento的模板语言(如:{{store url=””}}),fiter将翻译成实际的值
Magento中调用静态Block主要有两个地方。
2:这代码太长了呢,那你还可以这么写
<?php echo $this->getLayout()->createBlock(‘cms/block’)->setBlockId(‘order_form’)->toHtml() ?>
方法二:如何在CMS页面的Content中调用这个静态块呢?你可以采用以下方法
{{block type="cms/block" block_id="order-form" template="cms/content.phtml"}}
方法三:怎么样在layout中调用静态块呢
首先先设置block相应的xml内容:
<reference name=”footer”> <block type=”cms/block” name=”order_form” before=”-”> <action method=”setBlockId”><block_id>order_form</block_id></action> </block></reference>
然后在相应在模板文件.phtml中调用
getChildHtml('order_form');
http://www.hicoogle.com/magento-static-block-static-block-calls.html