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 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号