Is appending block by handle possible in Magento layout xml?
来源:互联网 发布:阿里云栖大会苏州 编辑:程序博客网 时间:2024/05/18 05:08
Is appending block by handle possible in Magento layout xml?
Inthe product list on Magento category page, I have a deeply nestedblocks for each product in the list. The structure is something like:
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
<!-- possibly more opening tags of nestings here -->
5
<
block
type
=
"..."
name
=
"product_prices"
template
=
"..."
/>
6
<!-- closing tags of nestings -->
7
</
block
>
8
</
block
>
9
</
block
>
If I want to add all above blocks to product list, there is a ready solution:
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.
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 thecontent in <my_product_list> and 3 category layouts get updatesautomatically.
It saves me a lot of time. However, since product list is also usedin search result and advanced search result, product list in the resultmisses 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.
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 wherethe duplication is when I want to make changes. So after a think, Icome up with an alternative:
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
<!-- Cannot merge to the above handle! Update handle does not work in the same handle when block is newly appended. -->
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
<!-- Cannot merge to the above handle! Update handle does not work in the same handle when block is newly appended. -->
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 withthe alternative, either. I would like the layout xml file recognisesomething like
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. Handlingthe layout of order, invoice, shipment, credit note is much more timetaking, becuase each document is rendered in many media, such ascustomer screen, admin screen, email, pdf. And if I have customdocuments, and custom documents are customised for suppliers, dropshipper, etc, an easy layout update mechanism will be very handy.
In a summary, I am trying to add child blocks by handle. At mement Iam intended to believe there is no way to trigger the layout xml intobatch adding blocks by handle without overriding Block abstract orLayout model, but there maybe some tricky way out there. If you knowit, let me know please.
- Is appending block by handle possible in Magento layout xml?
- Understanding layout.xml syntax in Magento
- Understanding layout.xml syntax in Magento
- magento layout 善用 local.xml
- Powerful block system in Magento
- "AND" in linq? is it possible?
- XML Handle by javax.xml.stream.*
- Fix layout.xml caching causing blocks to render other blocks in Magento
- Search by categories in Magento
- Magento布局layout.xml文件详解
- 探析magento的Layout xml Part 1
- 探析magento的Layout xml Part 2
- Magento布局layout.xml文件详解
- Magento布局layout.xml文件详解
- Magento布局layout.xml文件详解
- Magento布局layout.xml文件详解
- magento 通过layout文件 实现 block之间通信
- spark 读取alluxio: Caused by: java.io.IOException: Block 38416150429696 is not available in Alluxio
- Controller override and request rewrite in Magento
- Android 全局数据的应用
- What does backend type static mean in Magento?
- Winsock - CreateIoCompletionPort
- c++ 虚函数 工作机制 原理( virtual function )
- Is appending block by handle possible in Magento layout xml?
- 正式开始写打怪程序
- embedded matlab subset中的帧信号(frame-based signals)
- 操作系统总结之进程
- 把COM0变成可以用的普通串口
- custom tree node
- [Python 2 到 3 系列]此整型非彼整型
- [Python 2 到 3 系列]print 是函数
- Android开发之旅一 长按Button原理