I have added my custom module block in header in layout like below


   <reference name="header">
        <block type="core/template" name="pinsearch" as="pinSearch" template="pinsearch/pinsearch.phtml" output="toHtml"/>


<form action="<?php echo $this->getBaseUrl()."pinsearch/index/search"?>" method="get" id="search_pin_form">
<div class="input-box">
    <label for="search"><?php echo $this->__('Search:') ?></label>
     <input id="pinsearch" type="search" name="<?php echo "pin" ?>" value="" class="input-text required-entry" maxlength="" placeholder="<?php echo $this->__('Enter here...') ?>" />
    <button type="submit" title="<?php echo $this->__('Search') ?>" class="button search-button"><span><span><?php echo $this->__('Search') ?></span></span></button>

In frontend, I got my custom search form but not in header. This form showing after wrapper div block

enter image description here

When i add this block in footer only, its showing on both footer and after wrapper div block too.

I'm totally confusing. Have any idea why its proceeding like this?


When you add a block directly inside header block, magento will put your block just after all of it's child block that are added via other layout xml files that are processed before your pinsearch.xml.

Basically a header block contains following blocks by default. This is added via page.xml which will get processed before your pinsearch.xml

<block type="page/html_header" name="header" as="header">
    <block type="page/template_links" name="top.links" as="topLinks"/>
    <block type="page/switch" name="store_language" as="store_language" template="page/switch/languages.phtml"/>
    <block type="core/text_list" name="top.menu" as="topMenu" translate="label">
        <label>Navigation Bar</label>
        <block type="page/html_topmenu" name="catalog.topnav" template="page/html/topmenu.phtml"/>
    <block type="page/html_wrapper" name="top.container" as="topContainer" translate="label">
        <label>Page Header</label>
        <action method="setElementClass"><value>top-container</value></action>
    <block type="page/html_welcome" name="welcome" as="welcome"/>

see top.container (which is the wrapper block that you are mentioning, I hope) block is loading here. So when we add your block directly under header block, it just come just below welcome (This is not accurate. But if we consider page.xml only, this is true :-))

So if you need your block just inside the wrapper block, then what you need to is include your block inside wrapper block itself

   <reference name="header">
       <reference name="top.container">
            <block type="core/template" name="pinsearch" template="pinsearch/pinsearch.phtml"/>

Now suppose you need to include the block as child of header block itself, but need to display above the wrapper block (or any other child block), then what you need to do is.

   <reference name="header">
        <block type="core/template" name="pinsearch" as="pinSearch" template="pinsearch/pinsearch.phtml"/>

Then go to app/design/frontend/<package>/<theme>/template/page/html/header.phtml and then specify your block wherever you needed to display it as like this

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

Hope that clears your doubt.. Happy coding sis :-)

  • Now showing twice. Below navigation menu and after wrapper block – DRAJI Oct 17 '14 at 6:01
  • you need to remove the output="toHtml". I have edited answer accordingly – Rajeev K Tomy Oct 17 '14 at 6:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.