Home

Lullabot

Lullabot Ideas

We know stuff. We empower you to know stuff too.

On Site Drupal Training

We'll come to you! Graduate from your own on-site courses and become Drupalistas!

Theming based on http headers

Article by Ted SerbinskiJune 13, 2006 - 11:55pm

While working on the new MTV UK website, I ran into a rather strange problem. The theme on the MTV UK site is fairly complex, especially the main menu, since whatever menu item is current is taken out of context and placed elsewhere on the page. To do this, you look at what menu item is active in Drupal and extract it from the array.

But what do you do when you get a 404 "page not found"? How can you change your theme (e.g., the menu layout) based on this fact? A failsafe or default case would generally work, but in the case of MTV UK, their theme and requirements were too complex for a simple default. What we need is a way to intercept this 404 before it is shown so we can adjust our theme appropriately.

Impossible? Not hardly. But it's not intuitive either. Here's the scoop on the 2 lines of code needed for this trick:

<?php
  $headers
= drupal_set_header();
 
  if (
strstr($headers, 'HTTP/1.0 404 Not Found')) {
?>

Place that anywhere in your theme, and voila, you can alter your theme based on the fact the page isn't found. That would make it really easy to essentially change out your template in that case.

Works equally well for any type of header.

Happy theming!

Comments

June 14, 2006 - 12:02am Ted Serbinski

Just talked with chx on IRC,

Just talked with chx on IRC, he mentioned I should have used strpos() instead of strstr(). Performance boost, it's faster to return a boolean then a string. Thanks Karoly!

3dsl Eugen (not verified) on December 23, 2006 - 9:04pm

thx for tip

thx for tips :) its a great idea, well done!

greets and happy new year

About this 'bot

Ted Serbinski

Ted graduated from Cornell University with a degree in Information Science, Systems, and Technology and a minor in Computer & Electrical Engineering. While working on a 5 month coop at Intel in Massachusetts, Ted quickly realized that building web based tools was far more his forte than debugging...

more

Recent

Drupal Voices 160: Moshe Weitzman on Page Rendering in Drupal 7

Podcast 9.02.2010

Drupal Voices 159: John Albin Wilkins on Drupal 7 Theming

Podcast 9.01.2010

Drupal Voices 158: Emma Jane Hogbin on PHP for Designers

Podcast 8.31.2010

Command Line Basics: More Editing with Vi/Vim

Video 8.31.2010

Lullabot's Back to School Sale

Blog 8.30.2010

Popular

Drupal Voices 160: Moshe Weitzman on Page Rendering in Drupal 7

Podcast 9.02.2010

Drupal Voices 159: John Albin Wilkins on Drupal 7 Theming

Podcast 9.01.2010

Photo galleries with Views Attach

Article 6.01.2009

Drupal Voices 158: Emma Jane Hogbin on PHP for Designers

Podcast 8.31.2010

Announcing BeautyTips, a jQuery Tooltip Plugin

Article 10.20.2008
 
  • Home
  • Services
  • Events
  • Ideas
  • Store

Connect the Bots:

Twitter Facebook YouTube blip.tv All Posts Newsletter
  • Ideas
  • Blog
  • Podcasts
  • Videos
  • About
  • Contact
  • Jobs
  • Services
    • Training
  • Events
    • Training Workshops
    • Other Events
    • Conferences
    • Calendar
  • Products
    • Videos
    • Books
    • Swag
  • Ideas
    • Blog
    • Podcast
    • Videos
  • About
    • Philosophy
    • Team
    • Presskit
  • Contact
    • General
    • Work Inquiries
    • Mailing List