在MAGENTO中覆盖PHTML或布局核心文件

众所周知,Magento具有许多出色的功能,而Magento的功能之一就是分层导航过滤器。这些过滤器非常灵活,可扩展且动态,但是它们只有一个小问题,即它们不适合Google或搜索引擎。这些过滤器为网站上所有类别页面创建重复链接的原因,这意味着它最终在网站上创建了重复内容。正如您现在所说,Google不喜欢重复的内容,因此我们创建了一个模块(http://www.scommerce-mage.co.uk/magento-extensions/google-friendly-layered-navigation.html),该模块可以解决此问题,并且即将在Magento connect上提供,供您下载并提供一些反馈。

但是今天,我们将讨论如何在不更改默认主题的情况下覆盖Magento中的phtml或布局核心文件。

第1步

在您的本地文件夹下(在我们的示例中是/ app / local / Scommerce / LayeredNavigation下)创建一个新模块。现在,在etc文件夹中使用以下命令创建config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Scommerce_LayeredNavigation>
            <version>0.0.1</version>
        </Scommerce_LayeredNavigation>
    </modules>
    <frontend>
        <layout>
            <updates>
                <scommerce_layered>
                    <file>scommerce_layered.xml</file>
                </scommerce_layered>
            </updates>
        </layout>
    </frontend>
</config>

注意:您可以在文件中提供任何名称,但是我们建议您创建唯一的名称,因为如果您创建任何通用名称,则它可能与Magento的将来版本冲突。这就是为什么在我们的案例中,我们通过调用布局文件scommerce_layered.xml来选择安全选项

第2步

在app / design / frontend / base / default / layout下创建scommerce_layered.xml

<?xml version="1.0"?>
<layout version="0.1.0">
    <catalog_category_layered translate="label">
        <reference name="catalog.leftnav">
            <action method="setTemplate">
                <template>scommerce/layer/view.phtml</template>
            </action>
        </reference>
    </catalog_category_layered>
</layout>

在上述步骤中,我们指示Magento应该使用view.phtml而不是Magento的view.phtml进行分层导航,该分层导航通常位于以下路径app / design / frontend / base / default / template / catalog / layer /

第三步

这是最重要的一步!

在/etc/modules/Scommerce_LayeredNavigation.xml中创建模块文件

<Scommerce_LayeredNavigation>
    <active>true</active>
    <codePool>local</codePool>
</Scommerce_LayeredNavigation>

就这样,就这么简单。希望本文对您有所帮助。请留下您的评论,让我们知道您的想法?谢谢。

相关文章

0 0 投票数
文章评分
订阅评论
提醒
0 评论
内联反馈
查看所有评论