首先,您需要创建或更新 local.xml 文件,如果您没有 local.xml 文件,您可以在以下位置创建一个文件:
app->frontend->[包名]->[主题名]->layout->local.xml
创建后,您可以将我在这篇文章中的内容准确复制到该文件中,以开始如何使用它。
通过 LOCAL.XML 文件而不是 Catalog.xml 进行所有更新!这将使以后的升级变得更加容易。此外,您将能够在一个文件中快速查看对站点所做的所有更改。
下面的示例将其添加到根引用名称中,该名称将在所有页面上可用,但可以在 template->page->1column.phtml 或 2column-left.phtml 3column.phtml 等中轻松调用。
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<default>
<reference name="root">
<block type="core/template" name="top.search" as="topSearch" template="catalogsearch/form.mini.phtml"/>
</reference>
</default>
</layout>
然后使用您当前使用的方式调用它。
<?php echo $this->getChildHtml(‘topSearch’) ?>
现在您可以像上面的部分一样使用“引用名称”和“as”名称。例如,您可以使用下面类似的设置来引用页脚块以添加搜索功能。对于教育来说,“as”名称是 .phtml 文件中使用的名称。 “名称”是在 xml 文件中引用块的方式。所以在上面的例子中。我将搜索字段添加到根内容区域,然后在我的 .phtml 文件中使用“as”名称“topSearch”调用它
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<default>
<reference name="footer">
<block type="core/template" name="footer.search" as="footerSearch" template="catalogsearch/form.mini.phtml"/>
</reference>
</default>
</layout>
然后在 footer.phtml 中调用它
<?php echo $this->getChildHtml('footerSearch') ?>