【问题标题】:How to overwrite: catalog/product/view/type/default.phtml with XML Magento如何用 XML Magento 覆盖:catalog/product/view/type/default.phtml
【发布时间】:2013-08-01 01:30:08
【问题描述】:

我有一个简单的模块,我想覆盖一些模板文件。

例如,当我想通过 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,我尝试了任何方法,但没有任何效果。我的(很简单的)想法只是为新文件添加另一个&lt;action method="setTemplate"&gt;,但没有任何偏离。

谁能给我正确的代码?

【问题讨论】:

    标签: xml magento overwrite php


    【解决方案1】:

    要么将catalog/product/view/type/default.phtml 的副本放入app/design/frontend/default/&lt;yourdesign&gt;/template/ 下的设计覆盖中。
    或者,您可以先在布局 XML 中使用 unset,然后再重新定义要为其设置模板的块。

    看看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>
    

    【讨论】:

    • @user1897753 如果您编辑了自己的问题会更好。
    猜你喜欢
    • 1970-01-01
    • 2019-05-20
    • 2018-10-04
    • 2016-06-19
    • 1970-01-01
    • 1970-01-01
    • 2015-04-18
    • 2012-11-27
    • 1970-01-01
    相关资源
    最近更新 更多