Reputation: 5403
I am building my first custom Magento theme. It's slow going, but it is going. I got rid of the bar that originally held the mini search form on the home page and instead want to put the search form in my new header.
Here is the code for my header in header.phtml
:
<div id="header">
<a href="<?php echo $this->getUrl('') ?>" title="<?php echo $this->getLogoAlt() ?>" class="logo"><img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" /></a>
<div id="header-top">
<?php echo $this->getChildHtml('topSearch') ?>
<?php echo $this->getChildHtml('topLinks') ?>
</div>
<?php echo $this->getChildHtml('topMenu') ?>
</div>
But the search form is not rendering. Here is the site in question:
http://s1.mynewsitereview.com/
Many thanks!
Upvotes: 3
Views: 17450
Reputation: 754
I know this question is very old, but I gonna post my answer hoping it can help others with this same problem
In my case, I needed another search form on my footer so I opened
app/desing/frontend/base/default/layout/catalogsearch.xml
and copied:
<reference name="header">
<block type="core/template" name="top.search" as="topSearch" template="catalogsearch/form.mini.phtml"/>
</reference>
to: app/desing/frontend/my-theme/my-theme/layout/local.xml inside the default tags
<reference name="header">
<block type="core/template" name="top.search" as="topSearch" template="catalogsearch/form.mini.phtml"/>
</reference>
</default><!-- just to give a idea of the position of where you should paste this code -->
and then I changed it to:
<reference name="footer">
<block type="core/template" name="footer.search" as="footerSearch" template="catalogsearch/form.mini.phtml"/>
</reference>
</default>
then in my footer file I called:
<?php echo $this->getChildHtml('footerSearch') ?>
basically you have to tell where your theme needs to get the 'footerSearch' using the local xml, then you can call it thought php.
Upvotes: 4
Reputation: 953
First you need to create or update your local.xml file IF you do not have a local.xml file you can create one in
app->frontend->[Package Name]->[Theme Name]->layout->local.xml
Once this is created you can copy exactly what I have in this post into that file for a start of how to use one.
DO ALL UPDATES THROUGH A LOCAL.XML file not through catalog.xml !! This will make upgrades significantly easier later down the road. Additionally, you will be able to quickly see all changes you have made to your site in one file.
The below example will add it to the root reference name which will be available on all pages but easily called in template->page->1column.phtml or 2column-left.phtml 3column.phtml etc.
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<default>
<reference name="root">
<block type="core/template" name="top.search" as="topSearch" template="catalogsearch/form.mini.phtml"/>
</reference>
</default>
</layout>
Then call it using the way that you currently are using.
<?php echo $this->getChildHtml(‘topSearch’) ?>
Now you can use the "reference name" and "as" name like the above section. For example you could use the similar setup below to reference the footer block to add the search feature. For education "as" names are what are used in .phtml files. and "name" is how a block is referenced within xml files. So in the above example. I am adding the search field to the root content area and then calling it in my .phtml file with the "as" name of "topSearch"
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<default>
<reference name="footer">
<block type="core/template" name="footer.search" as="footerSearch" template="catalogsearch/form.mini.phtml"/>
</reference>
</default>
</layout>
Then call it in footer.phtml with
<?php echo $this->getChildHtml('footerSearch') ?>
Upvotes: 6