Theme Preprocess Functions: An Introduction

Updated: See first comment below for links to slides and code examples. ================================= How many times has this happened to you: You're theming a Drupal site, writing your CSS and making a few changes to the tpl files here and there. Everything is going great, then suddenly you realize you need to change one of those things that starts with a "$" inside those funny-looking <?php ?> tags. Panic! You exclaim... "Crap! Where does <?php print $content; ?> come from?! How do I change it?!" or maybe... "Crap! I need to have an extra CSS class on this body tag that depends on the taxonomy of the node on the page! Is that possible?!" or perhaps even... "Crap! I need a dropdown on a node edit form to change the way how a differet image field is rendered! How can I get that working?!" Sound familiar? Preprocess functions are the diplomats of Drupal themes. They are the missing link between what happens in the modules, and what gets sent to the template files. Goals: In this session, we'll dispel PHP fears, and get our feet wet with a little code that goes a long way to helping out with improving the flexibility of our theme. Prerequisites: Some experience with Drupal theming, general understanding of the templating system, good understanding of HTML and CSS, some basic familiarity with PHP. If you have a good grasp on the topics from from my proposed introduction to theming session, this is probably for you. This session was presented at BADCamp 2009, DrupalCon San Francisco 2010, DrupalCon Copenhagen 2010, BADCamp 2010, SandCamp 2011, and DrupalCamp Colorado 2011

Speakers

Time slot: 
Wednesday 10:45am-11:45am
Track: 
Design and user experience
Experience level: 
Intermediate
Questions answered by this session: 
Blimey! Where do theme template variables come from?
Aha! How do I take control of theme template variables?
Glorious! How do I create logic and pass information between templates?
I'm starving! Where are we going for lunch?
I'm bored! Do you want to go skiing?

Comments

Below are links to my slides and example code. Thanks for attending, enjoy the rest of the conference.

Slides: http://www.slideshare.net/c4rl/theme-preprocess-functions-an-introductio...
Theme code: http://dl.dropbox.com/u/21427810/jupiter-denver2012.tar.gz

Thanks. Great stuff.

41:30 onward is a blue screen for the remainder of the video

Colorado mountains