[英]Magento: Delaying Head Block from loading until my event has fired
我有兩個觀察員:
<events>
<controller_action_layout_load_before>
<observers>
<QuBit_UniversalVariable_Model_Page_Observer>
<type>singleton</type>
<class>universal_variable_main/observer</class>
<method>setUniversalVariable</method>
</QuBit_UniversalVariable_Model_Page_Observer>
</observers>
</controller_action_layout_load_before>
<catalog_block_product_list_collection>
<observers>
<QuBit_UniversalVariable_Model_Page_Observer>
<type>singleton</type>
<class>universal_variable_main/observer</class>
<method>setCatalogProductListing</method>
</QuBit_UniversalVariable_Model_Page_Observer>
</observers>
</catalog_block_product_list_collection>
</events>
我想要一個包含javascript的塊加載到我的Head中,但是需要使用Observer中收集的數據填充它。 我的問題是事件觸發之前,塊已加載。 我添加了一些日志記錄來證明這一點。
2013-07-12T07:18:44+00:00 DEBUG (7): loading setUniversalVariable
2013-07-12T07:18:44+00:00 DEBUG (7): loading template
2013-07-12T07:18:48+00:00 DEBUG (7): loading setCatalogProductListing
目前,我正在使用布局XML添加塊,我是否需要在setCatalogProductListing中以編程方式創建它,或者是否有其他方法可以防止在所有數據可用之前加載它?
甚至有可能在這里以編程方式創建它,還是已經確定了頭部?
提前致謝
在調度catalog_block_product_list_collection
事件時,已經輸出了head
,因此實際上沒有什么可以改變它的(或者實際上,它取決於列表塊的放置位置,但是在幾乎所有情況下,它將位於頭部之后)。
您必須直接處理布局和列表塊,才能在渲染頭部之前從集合中檢索數據,但是操作方式取決於您是將代碼應用於所有列表塊還是僅應用於類別列表(知道也可以從CMS內容中調用塊,因此在輸出相應的頁面/塊本身之前可能不存在)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.