Hacking Drupal 6.x’s front page (or any other page)

Drupal themeing is addictive. I’ve been so busy mucking with the new layout for one of my sites that I still haven’t gotten all of the content moved over, categorized, etc. I was really itching to fix “one last thing” on my site, and that was the front page.

My new layout uses the litejazz theme from RoopleThemes (though this tip should work with any theme, with only minor modification), which is super, super nice. It has three different color schemes, a million or so user regions to use, nice block formatting, lots of options and features… the works (thanks very much to the Roople folks for their work, btw).

Anyway, one thing I haven’t seen *any* themes do is provide an option to turn *off* the main content area on the home page (or any other page, for that matter). I wanted my home page to consist only of snapshots of various areas or aspects of the site, and the main navigation. I’m not doing some big news site or anything, so everything I’m doing fits into blocks. I don’t need the main content area. Turns out there’s a dead-simple way to get rid of it.

In your theme folder, whatever theme it is, there’s a file called page.tpl.php. Drupal (actually, PHPTemplate, Drupal’s theme engine) applies this page template to all of your site’s pages… unless it’s overriden!

Drupal’s theme system has a naming convention you can use to create page templates for any page or class of pages you want. So, if you want /node/8 to have a special look or feature that doesn’t exist anywhere else on the site, you can make a copy of page.tpl.php called page-node-8.tpl.php, alter the required parts, and /node/8, and only /node/8, will reflect those changes.

The same works for page-front.tpl.php, which is the home page of a drupal site. If you want to remove the main content, you can delete just that portion by removing lines that reference the $content variable. In the case of litejazz, I removed the entire ‘squeeze’ div, and now my footer touches the boxes in the top header area. Perfect!

  • Gayatri

    Thank you…such a simple piece of info…but, it took me hours….

  • http://mattrhysdavies.com Matt Rhys-Davies

    That’s pretty useful thanks – have been battling with Drupal for a few weeks now. Seems to have some upsides, and some downsides. Still not sure if I really like it yet.