Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Different header template for same layout
 
Dusan Stojanovic
Jr. Member
 
Total Posts:  6
Joined:  2009-04-21
 

Hi all, I need little help about Magento design…

I have made small changes in 1-column layout and start to use it. Now, I want to have one different template (phtml file) for header on home page and different on rest of pages, but I don’t now how. Any help?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Dusan Stojanovic
Jr. Member
 
Total Posts:  6
Joined:  2009-04-21
 

Any replay for this????

 
Magento Community Magento Community
Magento Community
Magento Community
 
dmitryseliv
Jr. Member
 
Total Posts:  20
Joined:  2009-03-20
 

Why do you need a second header?

What exactly you trying to output with second header template?

Dmitry

 
Magento Community Magento Community
Magento Community
Magento Community
 
Dusan Stojanovic
Jr. Member
 
Total Posts:  6
Joined:  2009-04-21
 

Hi Dmitry.

In one header is just beckground image (on home page), and on second is some other image with login form. So its just different template file, but i don’t know how to include it.

 
Magento Community Magento Community
Magento Community
Magento Community
 
dmitryseliv
Jr. Member
 
Total Posts:  20
Joined:  2009-03-20
 

Hi,

Here it goes.
1. Step One
/app/design/frontend/default/default/template/page/html

copy header.phtml
to something like header2.html

2. Step Two

/app/design/frontend/default/default/layout
edit page.xml

you can just copy existing Block

<block type="page/html_header2" name="header2" as="header2">
<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"/>
</block>
and change type and name only.

3. Step Three
/app/code/core/Mage/Page/
copy Header.php to Header2.php

4. Step Four
Edit Header2.php you will see this code at the begining

class Mage_Page_Block_Html_Header extends Mage_Core_Block_Template
{
public function _construct()
{
$this->setTemplate(’page/html/header.phtml’);
}

Change it to

class Mage_Page_Block_Html_Header2 extends Mage_Core_Block_Template
{
public function _construct()
{
$this->setTemplate(’page/html/header2.phtml’);
}

P.S it will output only HTML from header2.phtml
if you want to render any dynamic stuff then you need to edit other xml layout files.

You done.

 
Magento Community Magento Community
Magento Community
Magento Community
 
oldenwilde
Jr. Member
 
Total Posts:  3
Joined:  2009-08-10
 

This doesn’t work. When I tried it, I found that it alters the header for all the pages. As far as I can tell, the reason is because there’s nothing here that specifies “header2” should apply only to the home page. Also, when you say “you can just copy existing Block” in page.xml, it’s not clear whether you mean to change the existing block, or to keep the existing block and paste in a copy of it with the changes. I tried both ways; the first simply made my header disappear on all my pages, and the second caused a PHP error.

The only other solution I could find for changing the header on one page only turned out to be a clever cheat—it solved a particular problem by moving code out of the header and into the content block, not by actually changing the header. (http://www.lotusseedsdesign.com/blog/different-header-section-for-magento-homepage)

Changing the header for a specific page—in my case, trying to put a larger version of the store logo and a somewhat lengthy welcome message on the home-page header, but nowhere else—is such a simple need. Is there really no workable way to do it?

I’d like to know how to do this, but for now I’m moving on and just redesigning the home page so the welcome message is in the content block.

 
Magento Community Magento Community
Magento Community
Magento Community
 
oldenwilde
Jr. Member
 
Total Posts:  3
Joined:  2009-08-10
 

Oh, and also, I couldn’t find Header.php in /app/code/core/Mage/Page/
It was in /app/code/core/Mage/Page/Block/Html/

I’m using the Blank theme—don’t know if that matters.

 
Magento Community Magento Community
Magento Community
Magento Community
 
JeremyFP
Jr. Member
 
Total Posts:  24
Joined:  2009-09-25
Fort Wayne, IN
 

Oldenwilde, you can swap out the logo fairly easily on the homepage by loading an alternate block. Here’s how:

Go into yourtemplate/template/page/html/ and copy your logo.phtml file. Rename it something like logo-home.phtml, and then edit the file to reference your new image. Save the file to your server.

Open up yourtemplate/layout/page.xml and at the bottom, add a new block:

<cms_index_index>

    <
reference name="header">
        <
action method="unsetChild"><name>logo</name></action>
        <
block type="page/html_header" name="logo" as="logo" template="page/html/logo-home.phtml"/>
    </
reference>

</
cms_index_index>
(if the cms_index_index is already there, just add the reference).

That’s it. You’ve basically told the system to look for the existing logo code in the header, remove it, and replace it with your new code.

 
Magento Community Magento Community
Magento Community
Magento Community
 
oldenwilde
Jr. Member
 
Total Posts:  3
Joined:  2009-08-10
 

Thanks, Jeremy! I can see where ‘action method="unsetChild”’ could often come in handy when I need to create a local exception to a general template.

 
Magento Community Magento Community
Magento Community
Magento Community
 
denisslamalice
Jr. Member
 
Total Posts:  9
Joined:  2009-07-23
 

Hello,

I was looking for something like this but I didn’t really find what I searched. So I try to do something with my knowledges, I want to post this solution for others.
Why do I need a different header for the homepage?  It was because I followed the SEO tutotial of Yoast which says that it is good to have on the home page a H1 for the logo and change the H1 tag for other content more important like category title for the other pages. So to be able to do that, the header of the homepage has to be different from the other.

My homepage uses the “2column right” (and some other pages too), but in all my theme I never use the “2column left bar”. So first you need to copy the content of “2column right” in “2column left” (file in app/design/frontend/default/theme/template/). In fact your homepage will use the “2column left” file (which is now a 2column right as we have paste the content)

Now we have to copy the content of app/design/frontend/default/theme/template/html/header.phtml into the right place in our 2column-left.phtml like this (between the header comment):

<div class="wrapper">
    
<?php echo $this->getChildHtml('global_notices'?>
        
<!-- start header -->
        <
div class="header">
            <
div class="header-top-container">
                <
div class="header-top">
                    
<?php $theader Mage::getModel('Mage_Page_Block_Html_Header'); ?>
                    
<h1 id="logo"><a href="<?php echo $theader->getUrl('') ?>"><img src="<?php echo $theader->getLogoSrc() ?>" alt="<?php echo $theader->getLogoAlt() ?>" /></a></h1>
                    <
h5 class="slogan"><?php echo $this->__('www.website.com'?></h5>
                    <
class="no-display"><a href="#main"><strong><?php echo $this->__('Skip to Main Content'?> &raquo;</strong></a></p>
                    
<?php echo $this->getChildChildHtml('header''topSearch'?>
                    
<div class="quick-access">
                        <
class="welcome-message"><?php echo $theader->getWelcome() ?></p>
                        <
div class="shop-access">
                            
<?php echo $this->getChildChildHtml('header''topLinks'?>
                        
</div>
                    </
div>
                    
<?php echo $this->getChildChildHtml('header''store_language'?>
                    <?php 
echo $this->getChildChildHtml('header''headerCart'?>
                
</div>
            </
div>
            
<?php echo $this->getChildChildHtml('header''topMenu'?>
        
</div>
        <!-- 
end header -->

If you only do this it wont work because the getChildHtml is in the wrong place and the header model doesnt exist.

So we need to include the model of the Header.phtml with this line:

<?php $theader Mage::getModel('Mage_Page_Block_Html_Header'); ?>
We need to replace $this by $theader for getUrl, getLogoSrc, getLogoAlt and getWelcome.

You also have to change the getChildHtml to getChildChildHtml(’header’,’...’) because to get the block you have to go through the block header first.

And it is done, this 2column-left.phtml will be our homepage (select this template in the administration>CMS Page for the homepage) you can change whatever you want whithout modifying the header of the non homepage page… If you wish to modify the header of the others pages just edit app/design/frontend/default/theme/template/html/header.phtml

I am not a Magento professional, so if you find some improvements that I can do, you are welcome!!!

 
Magento Community Magento Community
Magento Community
Magento Community
 
ZAP
Jr. Member
 
Total Posts:  14
Joined:  2008-03-07
 

THANKS! This was a very helpful post. I was really struggling to implement an alternate home page layout before I found this.

 
Magento Community Magento Community
Magento Community
Magento Community
 
John Y
Jr. Member
 
Avatar
Total Posts:  30
Joined:  2008-12-02
 

worked for me! thanks for the post.

 
Magento Community Magento Community
Magento Community
Magento Community
 
girdy1974
Jr. Member
 
Total Posts:  1
Joined:  2012-09-18
 

Wow, this post was a HUGE help to me 2 years later. Thank you so much for posting the process dennisslamalice! Awesome!

 
Magento Community Magento Community
Magento Community
Magento Community
 
parth4234
Jr. Member
 
Total Posts:  1
Joined:  2012-12-06
 
dmitryseliv - 13 May 2009 03:02 PM

Hi,

Here it goes.
1. Step One
/app/design/frontend/default/default/template/page/html

copy header.phtml
to something like header2.html

2. Step Two

/app/design/frontend/default/default/layout
edit page.xml

you can just copy existing Block

<block type="page/html_header2" name="header2" as="header2">
<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"/>
</block>
and change type and name only.

3. Step Three
/app/code/core/Mage/Page/Block/Html
copy Header.php to Header2.php


4. Step Four
Edit Header2.php you will see this code at the begining

class Mage_Page_Block_Html_Header extends Mage_Core_Block_Template
{
public function _construct()
{
$this->setTemplate(’page/html/header.phtml’);
}


Change it to

class Mage_Page_Block_Html_Header2 extends Mage_Core_Block_Template
{
public function _construct()
{
$this->setTemplate(’page/html/header2.phtml’);
}


P.S it will output only HTML from header2.phtml
if you want to render any dynamic stuff then you need to edit other xml layout files.

You done.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top