我正在构建我的第一个定制的Magento主题。这是缓慢的,但它正在进行。我摆脱了最初在主页上持有迷你搜索表单的酒吧,而是希望将搜索表单放在我的新标题中。
以下是header.phtml
中我的头的代码
<div id="header">
<a href="<?php echo $this->getUrl('') ?>" title="<?php echo $this->getLogoAlt() ?>" class="logo"><img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" /></a>
<div id="header-top">
<?php echo $this->getChildHtml('topSearch') ?>
<?php echo $this->getChildHtml('topLinks') ?>
</div>
<?php echo $this->getChildHtml('topMenu') ?>
</div>
但是搜索表单没有呈现。以下是有关的网站:
http://s1.mynewsitereview.com/
非常感谢!
发布于 2014-01-28 23:47:52
首先,您需要创建或更新您的local.xml文件,如果您没有local.xml文件,可以在
app->前端->包名->主题名称->布局->local.xml
一旦创建了这个文件,您就可以准确地将我在这篇文章中的内容复制到该文件中,以便开始如何使用该文件。
通过LOCAL.XML文件进行所有更新,而不是通过catalog.xml!这将使以后的升级变得非常容易。另外,您还可以在一个文件中快速地看到对您的站点所做的所有更改。
下面的示例将将其添加到根引用名中,它将在所有页面上可用,但在template->page->1 Column.phtml或2列-左侧的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文件中使用的。"name“是如何在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') ?>
发布于 2013-10-20 00:59:19
我知道这个问题很老,但我会把我的答案发出来,希望它能帮助其他人解决同样的问题。
在我的例子中,我需要在我的页脚上另一个搜索表,所以我打开了
app/desing/frontend/base/default/layout/catalogsearch.xml
并复制:
<reference name="header">
<block type="core/template" name="top.search" as="topSearch" template="catalogsearch/form.mini.phtml"/>
</reference>
to:默认标记中的app/desing/frontend/my-theme/my-theme/layout/local.xml
<reference name="header">
<block type="core/template" name="top.search" as="topSearch" template="catalogsearch/form.mini.phtml"/>
</reference>
</default><!-- just to give a idea of the position of where you should paste this code -->
然后我把它改成:
<reference name="footer">
<block type="core/template" name="footer.search" as="footerSearch" template="catalogsearch/form.mini.phtml"/>
</reference>
</default>
然后在我的页脚文件中调用:
<?php echo $this->getChildHtml('footerSearch') ?>
基本上,您必须告诉您的主题需要在哪里使用本地xml获取“footerSearch”,然后可以将其称为thought。
https://stackoverflow.com/questions/12181827
复制相似问题