我有一个简单的模块,我想覆盖一些模板文件。
例如,当我想通过XML覆盖view.phtml时,我打开我的模块布局XML文件,只添加:
<catalog_product_view>
<reference name="product.info">
<action method="setTemplate">
<template>my-module-template-folder/catalog/product/view.phtml</template>
</action>
</reference>
</catalog_product_view>
但我也想覆盖:catalog/product/view/type/default.phtml,我已经尝试过任何东西,但都不起作用。我(从糟糕到简单)的想法只是为新文件添加另一个<action method="setTemplate">
,但没有什么不正常的。
有人能给我提供正确的代码吗?
要么将catalog/product/view/type/default.phtml
的副本放入app/design/frontend/default/<yourdesign>/template/
下的设计覆盖中
或者,您可以先在布局XML中使用取消设置,然后重新定义要为其设置模板的块。
看看app/design/frontend/base/default/layout/catalog.xml:268
<PRODUCT_TYPE_simple translate="label" module="catalog">
<label>Catalog Product View (Simple)</label>
<reference name="product.info">
<block type="catalog/product_view_type_simple" name="product.info.simple" as="product_type_data" template="catalog/product/view/type/default.phtml">
<block type="core/text_list" name="product.info.simple.extra" as="product_type_data_extra" translate="label">
<label>Product Extra Info</label>
</block>
</block>
</reference>
</PRODUCT_TYPE_simple>
您可能希望在PRODUCT_TYPE_simple
中引用product.info.simple
。
<PRODUCT_TYPE_simple>
<reference name="product.info">
<!-- <action method="unsetChild"><name>product.info.simple</name></action> -->
<action method="setTemplate">
<!-- app/design/frondend/default/<yourdesign>/template/my-module-template-folder/catalog/product/view.phtml -->
<template>my-module-template-folder/catalog/product/view.phtml</template>
</action>
</reference>
</PRODUCT_TYPE_simple>
回复后编辑:
谢谢你的回复。只是为了分享有效的结果:
<PRODUCT_TYPE_simple>
<reference name="product.info.simple">
<action method="setTemplate">
<template>my-modus-template-folder/catalog/product/view/type/default.phtml</template>
</action>
</reference>
</PRODUCT_TYPE_simple>