日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Magento调用静态块 static block

發布時間:2025/3/17 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Magento调用静态块 static block 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

靜態塊(static block),僅包含一些靜態的html內容,不涉及數據庫存取,比如像:一些文字和圖片鏈接,網站頁腳部分等。建立static block很簡單,Magento后臺提供一個功能,可以方便的創建、編輯、管理static block。可以在【管理員后臺】》【CMS】》【Static Blocks】菜單找到。

建立了static block后,如何在前端界面顯示呢?一是在Magento的layout文件中配置,然后在模板文件.phtml中通過調用 getChildHtml('block_id')輸出為html代碼。下面借助在Magento中系統內置的一個靜態塊footer_links來說明。

首先,在cms.xml layout文件中設置靜態塊:

<default> <referencename="footer"> <blocktype="cms/block"name="cms_footer_links"before="footer_links"> <!-- The content of this block is taken from the database by its block_id. You can manage it in admin CMS -> Static Blocks --> <actionmethod="setBlockId"><block_id>footer_links</block_id></action> </block> </reference> </default>

然后,在模板文件footer.phtml中輸出:

// echo $this->getChildHtml(); echo $this->getChildHtml('footer_links');

另外一種方式更簡單,不需要配置layout文件,就可以直接在php代碼中輸出靜態塊內容:?

echo $this->getLayout()->createBlock('cms/block')->setBlockId('footer_links')->toHtml();

????確實很簡單,但Magento在背后做了大量的工作,在文件app/code/core/Mage/Cms/Block/Block.php中,可以看到這些辛苦的步伐:

/** * Cms block content * * @category Mage * @package Mage_Cms * @author Magento Core Team <core@magentocommerce.com> */ classMage_Cms_Block_Block extendsMage_Core_Block_Abstract { protectedfunction_toHtml() { if(!$this->_beforeToHtml()) { return''; } $html= ''; if($blockId= $this->getBlockId()) { $block= Mage::getModel('cms/block') ->setStoreId(Mage::app()->getStore()->getId()) ->load($blockId); if(!$block->getIsActive()) { $html= ''; } else{ $content= $block->getContent(); $processor= Mage::getModel('core/email_template_filter'); $html= $processor->filter($content); } } return$html; } }

轉載于:https://my.oschina.net/u/234530/blog/56430

總結

以上是生活随笔為你收集整理的Magento调用静态块 static block的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。