is appending block by handle possible in magento layout xml?-尊龙官方平台

is appending block by handle possible in magento layout xml?

el/2024/3/25 14:28:40

 

is appending block by handle possible in magento layout xml?

in the product list on magento category page, i have a deeply nested blocks for each product in the list. the structure is something like:

view source print ?
1 < block type = "..." name = "product_in_category" template = "..." >
2   < block type = "..." name = "product_options_selector" template = "..." >
3   < block type = "..." name = "product_price_container" template = "..." >
4  
5   < block type = "..." name = "product_prices" template = "..." />
6  
7   block >
8   block >
9 block >

if i want to add all above blocks to product list, there is a ready solution:

view source print ?
01 < my_product_list >
02   < reference name = "product_list" >
03   < block type = "..." name = "product_in_category" template = "..." >
04   < block type = "..." name = "product_options_selector" template = "..." >
05   < block type = "..." name = "product_price_container" template = "..." >
06   < block type = "..." name = "product_prices" template = "..." />
07   block >
08   block >
09   block >
10   reference >
11 my_product_list >

once i put them together as a handle, i can easily duplicate them to 3 category layouts.

view source print ?
01 < catalog_category_default >
02   < update handle = "my_product_list" />
03 catalog_category_default >
04  
05 < catalog_category_layered >
06   < update handle = "my_product_list" />
07 catalog_category_layered >
08  
09 < catalog_category_layered_nochildren >
10   < update handle = "my_product_list" />
11 catalog_category_layered_nochildren >

so every time i make changes to product list, i only change the content in and 3 category layouts get updates automatically.

it saves me a lot of time. however, since product list is also used in search result and advanced search result, product list in the result misses updates because it is named as “search_result_list” instead of “product_list”. the instance reaction is duplicating codes for “search_result_list”, i.e.

view source print ?
01 < my_product_list_of_result >
02   < reference name = "search_result_list" >
03   < block type = "..." name = "product_in_category" template = "..." >
04   < block type = "..." name = "product_options_selector" template = "..." >
05   < block type = "..." name = "product_price_container" template = "..." >
06   < block type = "..." name = "product_prices" template = "..." />
07   block >
08   block >
09   block >
10   reference >
11 my_product_list_of_result >
12  
13 < catalogsearch_result_index >
14   < update handle = "my_product_list_of_result" />
15 catalogsearch_result_index >
16  
17 < catalogsearch_advanced_result >
18   < update handle = "my_product_list_of_result" />
19 catalogsearch_advanced_result >

i do not like duplication, because i keep forgetting when and where the duplication is when i want to make changes. so after a think, i come up with an alternative:

view source print ?
01 < every_product >
02   < reference name = "product_in_category" >
03   < block type = "..." name = "product_options_selector" template = "..." >
04   < block type = "..." name = "product_price_container" template = "..." >
05   < block type = "..." name = "product_prices" template = "..." />
06   block >
07   block >
08   reference >
09 every_product >
10  
11 < add_every_product_to_category >
12   < reference name = "product_list" >
13   < block type = "..." name = "product_in_category" template = "..." />
14   reference >
15 add_every_product_to_category >
16
17 < add_every_product_to_category >
18   < update handle = "every_product" />
19 add_every_product_to_category >
20  
21 < add_every_product_to_result >
22   < reference name = "search_result_list" >
23   < block type = "..." name = "product_in_category" template = "..." />
24   reference >
25 add_every_product_to_result >
26
27 < add_every_product_to_result >
28   < update handle = "every_product" />
29 add_every_product_to_result >
30  
31 < catalog_category_default >
32   < update handle = "add_every_product_to_category" />
33 catalog_category_default >
34  
35 < catalog_category_layered >
36   < update handle = "add_every_product_to_category" />
37 catalog_category_layered >
38  
39 < catalog_category_layered_nochildren >
40   < update handle = "add_every_product_to_category" />
41 catalog_category_layered_nochildren >
42  
43 < catalogsearch_result_index >
44   < update handle = "add_every_product_to_result" />
45 catalogsearch_result_index >
46  
47 < catalogsearch_advanced_result >
48   < update handle = "add_every_product_to_result" />
49 catalogsearch_advanced_result >

you will see the code is messy. that is why i am not satisfied with the alternative, either. i would like the layout xml file recognise something like

view source print ?
01 < my_product_layout >
02   < block type = "..." name = "product_in_category" template = "..." >
03   < block type = "..." name = "product_options_selector" template = "..." >
04   < block type = "..." name = "product_price_container" template = "..." >
05   < block type = "..." name = "product_prices" template = "..." />
06   block >
07   block >
08   block >
09 my_product_layout >
10  
11 < add_layout_to_category >
12   < reference name = "product_list" >
13   < layout handle = "my_product_layout" />
14   reference >
15 add_layout_to_category >
16  
17 < add_layout_to_result >
18   < reference name = "search_result_list" >
19   < layout handle = "my_product_layout" />
20   reference >
21 add_layout_to_result >
22  
23 < catalog_category_default >
24   < update handle = "add_layout_to_category" />
25 catalog_category_default >
26  
27 < catalog_category_layered >
28   < update handle = "add_layout_to_category" />
29 catalog_category_layered >
30  
31 < catalog_category_layered_nochildren >
32   < update handle = "add_layout_to_category" />
33 catalog_category_layered_nochildren >
34  
35 < catalogsearch_result_index >
36   < update handle = "add_layout_to_result" />
37 catalogsearch_result_index >
38  
39 < catalogsearch_advanced_result >
40   < update handle = "add_layout_to_result" />
41 catalogsearch_advanced_result >

handling the layout of product list is not the worst case. handling the layout of order, invoice, shipment, credit note is much more time taking, becuase each document is rendered in many media, such as customer screen, admin screen, email, pdf. and if i have custom documents, and custom documents are customised for suppliers, drop shipper, etc, an easy layout update mechanism will be very handy.

in a summary, i am trying to add child blocks by handle. at mement i am intended to believe there is no way to trigger the layout xml into batch adding blocks by handle without overriding block abstract or layout model, but there maybe some tricky way out there. if you know it, let me know please.


http://www.ngui.cc/el/5126494.html

相关文章

扎西拉姆的诗

《扎西拉姆的诗》 你见,或者不见我 我就在那里   不悲不喜 你念,或者不念我 情就在那里   不来不去 你爱,或者不爱我 爱就在那里   不增不减 你跟,或者不跟我 我的手就在你手里   不舍不弃 来我的怀里 …

grid报错clause is ambiguous问题-----------------摘自精东

magento深入理解-grid报错clause is ambiguous问题 我记得之前没少讲过grid,今天在写grid遇到这样一个错误,将解决办法分享下。 sqlstate[23000]:integrity constraint violation:1052column increment_idin where clause is ambiguous 这个…

有点累了!

是不是自己累了,是不是真的累了!! 天天就搞些工作的事情,弄的自己没一点幸福感,对于工作带来的喜悦也是不会持续很久!半天就散 没有对象的自己,对父亲这个词语感觉很亲切,很想成为…

magnto获取当前店铺和店铺配置的方法---转

magnto获取当前店铺和店铺配置的方法 开发中常常用到获取当前店铺的id或者获取当前店铺的配置。其实非常的简单,看代码: 1、获取店铺 $storemage::app()->getstore();你可以print一下$store,它是mage_core_model_store对象,…

关于magento的时间/时区问题--------转自精东

关于magento的时间/时区问题 今天同事研究为啥保存的时间不是东八区时间,由此引来的话题。 magento整个系统中使用utc时间,即通用协调时(utc, universal time coordinated)。这样保证在不同的视图或者store里使用的时间与本地时间一致,在系…

magento如何使用和设置cookiesession

magento如何使用和设置cookie&session 给大家介绍两个magento的核心对象-mage_core_model_cookie & mage_core_model_session 首先介绍mage_core_model_cookie,这个对象主要是用来设置cookie的,里面主要下列方法: publi…

magento数据转移/换服务器/换域名

magento数据转移/换服务器/换域名 1.进入原来的phymyadmin,选择magento的那个数据库,在右边的标签上点击导出。 2.全选所有的表,结构那儿都勾上:添加 drop table,如果不存在就增加,添加 auto_increment 值…

magento -- 客户无法使用contact us 发邮件

magento -- 客户无法使用contact us 发邮件 - unable to submit your request. please, try again later magento的contact us是一个非常重要的一个功能,当在线客服不在时,客户可以通过contact us发送邮件来联系尊龙官方平台。问题是,总是会出来这…

打开magento开发的调试模式

打开magento开发的调试模式(开发者模式) 做magento开发的人都会有这样的经验,有时候了出错了,magento给出的是一个空白页(blank page),或者是停留在某个页面,无动于衷.经验丰富的php程序员自然是知道如何去让magento在出现这种情况时给我们足够多的信息以帮助调试. 事实上,打开…

magento 输出操作成功与否的 message 信息 ,

在程序中总能看到一些输出的信息,比如:商品加入购物车,后出现 这种情况,代码如下: $session mage::getsingleton(core/session); 成功: $session->addsuccess($this->__(your review has bee…
网站地图