dtqi87613 2013-11-06 21:09
浏览 99
已采纳

如何在Magento的其他目录/页面中访问$ this-> getChildHtml()等方法?

All I want to do is move a search box. This search box is currently displayed in the header, directly next to the logo, and is generated by the following code:

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

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

I would like this search box inline with the navigation links, which are located in top.phtml which is located in another directory. But when I use the code

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

the search box does not appear. I understand that this is because the meaning of $this has changed, but what I don't understand is how to display the search box? What do I replace $this with?

I tried replacing it with Mage_Page_Block_Html_Header since that was the definition of $this in header.phtml, but to no avail. Can anybody point me in the right direction, or provide an explanation as to how I access methods once the definition of $this has changed?

  • 写回答

1条回答 默认 最新

  • dongnaosuan5407 2013-11-06 21:52
    关注

    You need to make layout update and include block topSearch into block containing top.phtml. Look into app/design/frontend/.../layouts/...xml files, find how topSearch is declared and then find where the block using top.phtml template is declared. Then move topSearch block as a child of top block. I mean add layout xml update like this:

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

    Another solution is try next in your template:

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

    If it would not work then find in layouts topSearch block and try to use in code above name of block instead of alias.

    You can read more about Magento view level here: http://www.magentocommerce.com/wiki/4_-_themes_and_template_customization/0_-_theming_in_magento/designing-for-magento

    Good luck!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?