Magento Forum

Trying to Move the Search Box
 
Primary Numbers
Jr. Member
 
Total Posts:  17
Joined:  2007-09-03
 

I’m trying to move the search box around some....

This block is found in default.xml

<block type="core/template" name="top.search" as="topSearch">
<action method="setTemplate"><template>catalogsearch/form.mini.phtml</template></action>
</block>

My first instinct was to just remove this block from the header block and put it by it self.  I figured then I could call it seperately inside of the 3columns.phtml file wherever I wanted using:

<?=$this->getChildHtml('topSearch')?>

This however does not work.... I know I’m missing something simple… but what is it smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
_
Sr. Member
 
Total Posts:  152
Joined:  2007-08-31
 

Try to use

<?=$this->getLayout()->getBlock('top.search')->toHtml()?>

instead of

<?=$this->getChildHtml('topSearch')?>

so you’ll be able to put the search bar anywhere in your template.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Scott
Guru
 
Avatar
Total Posts:  333
Joined:  2007-08-31
Northwest Ohio
 

Moshe said that they may change the method that gets the HTML of the child block. Personally, I haven’t been able to get an HTML block’s HTML to render without using Adam’s above code. Moshe mentioned that they may change this to simply getBlockHtml() which I would highly suggest. Your average designer wouldn’t know to use <?=$this->getLayout()->getBlock('top.search')->toHtml()?> and is probably already daunted by use of the XML blocks, and the associated learning curve of them right from the start.

wink

 
Magento Community Magento Community
Magento Community
Magento Community
 
upakarti
Sr. Member
 
Avatar
Total Posts:  264
Joined:  2008-06-25
Denpasar, Bali Indonesia
 

Thanks @A.Piotrowski (Lento.pl):
The code is useful to adjust the search box wherever I like - simple and helpful.

 
Magento Community Magento Community
Magento Community
Magento Community
 
fegizii
Sr. Member
 
Total Posts:  160
Joined:  2009-01-21
 

Just to clarify:

in this line of code:  ?=$this->getLayout()->getBlock(’top.search’)->toHtml()?> what goes between parentheses?

?=$this->getLayout( WHAT GOES HERE )->getBlock(’top.search’)->toHtml( WHAT GOES HERE )?>

i’m such a noob lol

plz hlp

 
Magento Community Magento Community
Magento Community
Magento Community
 
MarGera332
Jr. Member
 
Total Posts:  15
Joined:  2008-11-04
 

Can anyone shed some light on how this works? Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
theRiley
Jr. Member
 
Avatar
Total Posts:  8
Joined:  2009-12-16
 

Awesome solution thanks _

I would also like more info on this mechanism if anyone can give more input.

Thanks again!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Template fans
Guru
 
Total Posts:  446
Joined:  2009-11-02
 

Thank you.

 
Magento Community Magento Community
Magento Community
Magento Community
 
lynnspain
Member
 
Avatar
Total Posts:  65
Joined:  2008-08-07
Baleares, Spain
 

Hi this may help you.

http://www.magentocommerce.com/design_guide/articles/intro-to-layouts

 
Magento Community Magento Community
Magento Community
Magento Community
 
brianb421
Sr. Member
 
Total Posts:  196
Joined:  2009-04-23
 

<?=$this->getLayout()->getBlock('top.search')->toHtml()?>
worked great for me.

 
Magento Community Magento Community
Magento Community
Magento Community
 
chaddro
Jr. Member
 
Total Posts:  25
Joined:  2007-12-20
 

I am modifying the modern template and having trouble removing the search from the cookie-crumbs line:

I have figured out how (from this thread) to get the search into the upper portion of the header, but I cannot find where
in the xml files to remove the lower duplicated search.  See screen capture.

Note that I am using the new 1.4.0.1 magento and the updated modern template for 1.4.0.1.

Image Attachments
screencap.png
 
Magento Community Magento Community
Magento Community
Magento Community
 
harelme2
Jr. Member
 
Total Posts:  3
Joined:  2010-02-11
 

I think removing/commenting out the following line from app/design/frontend/modern/default/template/page/html/header.phtml should do it:

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

Please let me know if this helps.

 
Magento Community Magento Community
Magento Community
Magento Community
 
gKat
Jr. Member
 
Total Posts:  22
Joined:  2010-05-21
 
_ - 15 September 2007 05:54 AM

Try to use

<?=$this->getLayout()->getBlock('top.search')->toHtml()?>

instead of

<?=$this->getChildHtml('topSearch')?>

so you’ll be able to put the search bar anywhere in your template.

Worked a treat, ta

 
Magento Community Magento Community
Magento Community
Magento Community
 
hancoha
Jr. Member
 
Total Posts:  20
Joined:  2010-04-25
Auburn, Alabama
 
gKat - 08 June 2010 05:14 AM

_ - 15 September 2007 05:54 AM
Try to use

<?=$this->getLayout()->getBlock('top.search')->toHtml()?>

instead of

<?=$this->getChildHtml('topSearch')?>

so you’ll be able to put the search bar anywhere in your template.

Worked a treat, ta

This works but I would like to know why using the getBlock statement is better than using getChildHtml? Does one perform better than the other? What are the advantages and disadvantages? Thanks in advance!

@Primary Numbers You need to open catalogsearch.xml in the layout and change the following:

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

to

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

You then should be able to use

<?php echo $this->getChildHtml('topSearch'?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
deasach
Jr. Member
 
Total Posts:  9
Joined:  2010-01-11
 

Is there a way of removing the Search Box from the header through the XML layout mechanism without removing it entirely? I want to move the search box to the footer and have used the following:

<reference name="footer">

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

    </
reference>
which displays the box in the footer, but if I now try to remove it from the header with:

<reference name="header">
       
                <
remove name="top.search"/>

        </
reference>

it removes both the search box in the footer as well as the one in the header. Is it necessary to hack the template file (page/html/header.phtml) to remove the following method call:

$this->getChildHtml(’topSearch’)

to achieve what I want or can it be done more elegantly with an XML instruction?

 
Magento Community Magento Community
Magento Community
Magento Community
 
hp7
Jr. Member
 
Total Posts:  18
Joined:  2009-04-23
 
deasach - 07 October 2010 06:14 AM

Is there a way of removing the Search Box from the header through the XML layout mechanism without removing it entirely? I want to move the search box to the footer and have used the following:

<reference name="footer">

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

    </
reference>
which displays the box in the footer, but if I now try to remove it from the header with:

<reference name="header">
       
                <
remove name="top.search"/>

        </
reference>


it removes both the search box in the footer as well as the one in the header. Is it necessary to hack the template file (page/html/header.phtml) to remove the following method call:

$this->getChildHtml(’topSearch’)

to achieve what I want or can it be done more elegantly with an XML instruction?

Change

<reference name="footer">

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

    </
reference>
To this
<reference name="footer">

        <
block type="core/template" name="footer.search" as="footerSearch" template="catalogsearch/form.mini.phtml" />

    </
reference>
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top