1

我想要做的就是移动一个搜索框。该搜索框当前显示在标题中,直接在徽标旁边,由以下代码生成:

<?php echo $this->getChildHtml('topSearch') ?>

/app/design/frontend/MYTHEME/default/template/page/html/header.phtml

我希望这个搜索框与导航链接内联,这些导航链接top.phtml位于另一个目录中。但是当我使用代码时

<?php echo $this->getChildHtml('topSearch') ?>

搜索框不出现。我明白这是因为 的含义发生$this了变化,但我不明白的是如何显示搜索框?我用什么代替$this

我尝试将其替换Mage_Page_Block_Html_Header为 header.phtml 中的定义$this,但无济于事。任何人都可以为我指出正确的方向,或者解释一旦定义$this发生变化我如何访问方法?

4

1 回答 1

2

您需要进行布局更新并将块 topSearch 包含到包含 top.phtml 的块中。查看 app/design/frontend/.../layouts/...xml 文件,找到 topSearch 是如何声明的,然后找到使用 top.phtml 模板声明的块的位置。然后将 topSearch 块作为 top 块的子级移动。我的意思是像这样添加布局xml更新:

<default>
    <reference name="catalog.topnav">
        <block type="core/template" name="top.search" as="topSearch" template="catalogsearch/form.mini.phtml"/>
    </reference>
</default>

另一种解决方案是在您的模板中尝试下一步:

echo $this->getLayout()->getBlock('top.search')->toHtml()

如果它不起作用,则在布局中查找 topSearch 块并尝试在块名称上方的代码中使用而不是别名。

您可以在此处阅读有关 Magento 视图级别的更多信息:http: //www.magentocommerce.com/wiki/4_-_themes_and_template_customization/0_-_theming_in_magento/designing-for-magento

祝你好运!

于 2013-11-06T21:52:56.320 回答