Hello!

I created my own theme with a page.tpl.php file. It consists of header, navigation, content and footer. I use this layout for all my pages.

However, now I want to have a different layout for the front page. Many tutorials advice to create a copy of page.tpl.php and style it individually. Sure, this will work, but in my case just the layout of the content changes (header, navigation and footer will stay the same). So this approach would end up in a maintenance nightmare.

What is the best way to organize page.tpl.php such, that I define header, navigation and footer just once, but can have different layouts for the content area? Is there any best practice? Should I use some sort of require_once('header.php') PHP code?

Regards,
Actron

Comments

nevets’s picture

The panels module is good for this. You make a panel page, given it path, select a layout and assign content to the panes. You would then under site information make this page your default home page

Actron’s picture

Thanks for your reply, but ain't that cracking nuts with a sledgehammer? I just want to do this for the front page and the panels module seems to be very complex. There must be an easier way, I guess. Maybe even programatically without any new modules.

Jeff Burnz’s picture

There's not enough detail in your post to accurately answer this, for example what changes are to be made to what (precisely what is to change and how etc).

I think you will find that one additional template is not that bad an option, when all things are weighed up, it just depends on what you need to change - it could be done from a process function, alter etc but we don't have the details to offer such advice.

findmashmind’s picture

if you want to add different layout for content area you should change the node template. node.tpl.php

ergunk’s picture

Add .front before classes/IDs/elements for layouts which you want style different only for front page.

For example; if you want to make background color of nodes red only in front page:

.front .node {
background-color: #c00;
}

or all content area...

.front #content {
background-color: #c00;
}

etc.

You can use this for any other classes/IDs/elements, content types etc. Look body class array in your page's source. You can create special CSS codes for that class names. For example, in this page's code it is like this

<body class="not-front logged-in page-node node-type-forum no-sidebars drupalorg-site-main">

So we could use special styles for any of these classes by adding them before our existing styles.


Mediasaur | http://www.mediasaur.com/en | http://twitter.com/mediasaur


Before asking for help, please read this http://slash7.com/2006/12/22/vampires/ and don't be a "Help Vampire". :)