Homepage template quirks in Drupal 7

The Engagement 4Cast

Homepage template quirks in Drupal 7

Avatar

Blog

10/06/2011

Alexis Findiesen

So it’s time to theme another Drupal site. You’ve got your base theme installed, customized, and ready to roll (we like to use Zen). You’ve got your interior page template styled and slick, now comes the homepage…usually a bit different from the rest of the site design. 
In Drupal 6, everything is pretty straightforward in terms of how you set up your homepage template from the default interior page template (duplicate the page.tpl.php file and call it page-front.tpl.php and make sure both are uploaded), set blocks to display (or not) based on simple logic and options within the block editing area, etc. In other words, everything behaves as expected…smoooooooth sailing.

However, when going through the same workflow in Drupal 7, I noticed some things seemed amiss and not documented very well. I discovered after much research that to create your homepage template and have it register as such, you now had to use a double hyphen in the nomenclature mentioned above: “page–front.tpl.php” versus “page-front.tpl.php” which felt random.

I also noticed that page content was being controlled by a new block called “Main page content” which could be dragged into a preferred region to populate the site with content. Great! Once I was ready to set up the homepage, which didn’t need any type of dynamic content “loop” pumped in, I went into the block settings and told it to display on every page except the front. Then I set up all my homepage-specific blocks and set them to only display on the homepage. Voila.

Unfortunately the content block was still populating the homepage with mysterious information despite my settings above instructing it to go away. After numerous refreshes, cache flushing, double and triple checking code, pulling out hair, etc. I realized I was doing everything right…but it still wasn’t working. Digging around online, I stumbled across a forum full of people with an almost identical problem: how do we turn off this content we don’t want in the homepage content region?

As noted in comment #48, the best solution I could find and wanted to share was to create a custom region for the homepage which wouldn’t be present on any of the interior pages, thereby removing any possibility that content I didn’t explicitly place there would ever show up. I removed the “content” region from the homepage template and replaced it with something obvious like “content_home” and updated my .info file to define this new region. After pushing these updated files to the development server and flushing caches, I was able to drag the “Main page content” block and any other blocks I wanted on interior pages only to the regular “content” region and blocks I wanted on the homepage to the “content_home” region. No more fooling with the “show on every page except <front>” options per block that were being ignored, etc. This has worked like a charm for me, and I’ve tried to share my method with colleagues as it comes up in new projects.

If you poke around the forum link above, you’ll see alternate ideas and suggestions, some of which may be good solutions as well. Let us know if you’ve had similar experiences with quirky Drupal behavior and how you tackled them!

About the Engagement 4Cast

4Site Interactive Studios is a talented troupe of web professionals who are passionate about creating tools to support digital marketers. We love to hear from our community! Reach out to us with your thoughts and questions. And don’t forget to subscribe below to get notified when we post new blogs – no spam, just content👍🏼

Subscribe & stay ahead of the crowd with sage marketing tips and predictions.