zoukankan      html  css  js  c++  java
  • Magento中,调用静态块的几种方法

    在后台创建一个order_form静态块
    Block Title :Order Form
    Identifier :order_form
    Status :Enabled
    Content :自定义内容

    1.如果要在.phtml文件中直接调用这个静态块,那可以采用以下方法

    1. <?php  
    2. $block = Mage::getModel('cms/block')  
    3.  ->setStoreId(Mage::app()->getStore()->getId())  
    4.  ->load('order_form');  
    5. $content = $block->getContent(); // Block的原始内容已经获得  
    6.   
    7. $processor = Mage::getModel('core/email_template_filter');  
    8. echo $html = $processor->filter($content);  
    9. ?>  


    Mage::getModel('core/email_template_filter')->filter()是必须的,因为Static Block里可能包含Magento的模板语言(如:{{store url=""}}),fiter将翻译成实际的值
    Magento中调用静态Block主要有两个地方。
    是否感觉这代码太长了呢,那你还可以这么写

    1. <?php echo $this->getLayout()->createBlock(‘cms/block’)->setBlockId('order_form')->toHtml() ?>   

    2.如何在CMS页面的Content中调用这个静态块呢?你可以采用以下方法

    1. {{block type="cms/block"  name="cms_test_block"  block_id="order_form" }}   


    将里面order_form改成你的静态块对应的block_id则可

    3.怎么样在layout中调用静态块呢?

    [xhtml] view plaincopy
    1.  <reference name="footer">  
    2.     <block type="cms/block" name="order_form" before="-">  
    3.         <action method="setBlockId"><block_id>order_form</block_id></action>  
    4.     </block>      
    5. </reference>   

     
     
    到此,你应该能够灵活的运用magento中的静态块了吧!

  • 相关阅读:
    inline必须在定义、实现都标记
    循环数组优化队列
    游程编码的优化
    新密码
    I Could Have Danced All Night
    strtok源码 bitset 空间压缩
    XOR Swap
    补码
    临时邮箱
    linux中find批量删除空文件夹
  • 原文地址:https://www.cnblogs.com/focai/p/4166778.html
Copyright © 2011-2022 走看看