The switch statement is a common control structure in programming languages. You will have undoubtedly seen a few if you spend any time working with Drupal modules or themes. Switch statements love to hangout with a theme's template.php file in preprocess hooks. Consider, if you will, the following:

Pancakes for breakfast!
This snippet demonstrates how to create the CSS3 style sticky notes similar to those found on this site. See a demo at
Three monitors
Every once in a while I need to recreate the default apache virtualhost file. Here it is!
Personalized pancake

If you are a regular user of Microsoft's Windows operating system, then you have undoubtably been greeted with this popup:

Many languages support a control structure called the switch statement that is an alternative for if/else-if. Python, however, has no switch statement. Does that mean we must always resort to using a sequence of if/elif? Not necessarily! Python uses one of the most efficient hashing algorithms for it's dictionary type. We can use a dictionary to create a type of switch statement that is both efficient and very elegant. Consider the following sequence of if/elif to find a holiday for a given month.
month = 'March'

if month.lower() == "january":


Subscribe to Caleb Thorne RSS