introduction to theme preprocess functions
DESCRIPTION
TRANSCRIPT
Introduction to Theme Preprocess Functions
BADCamp 18 Oct 2009
Carl Wiedemann drupal.org user c4rl
Preprocess in Theory
Theme Dilemmas
What do we do if this is insufficient?
<div class="content"> <?php print $content; ?> </div>
How can we create more useful theme content?
<div class="content"> <?php print $my_content; ?> </div>
<div class="<?php print $my_classes; ?>"> <?php print $my_content; ?> </div>
How can we keep our theme contextual?
How can we create more useful theme content?
Preprocess
Preprocess makes content
flexible
<?php print $my_content; ?>
Preprocess makes theming
dynamic
class="<?php print $my_classes; ?>"
Preprocess keeps templates
clean
if else foreach while switch =
So, when does preprocess happen?
Processing Request
Raw Data
Processing
Return Data
Database
Modules Request
Raw Data
Processing
Return Data
Formatted Data
HTML!
Database
Modules
Theme
Request
Raw Data
Processing
Return Data
Formatted Data
HTML!
Database
Modules
Theme
Request
Preprocess in Practice
Firebug Web Developer Toolbar
admin_menu devel
devel_themer
Demo
template.php mytheme_preprocess_page
dsm mytheme_preprocess_node
theme.inc
Exploring
Demo
Manually creating $myvar
$submitted
Demo
Specifying additional templates
Demo
Contextual CSS
Demo
Working with CCK $content
Important things to remember:
dsm() delays on preprocess_page()
Clear cache when adding new tpl files and adding functions to template.php
Use check_markup() and check_plain() on data that may be unsafe
Questions and Thanks Thanks to Matt Tucker (ultimateboy) for inspiring this talk
Demo Photography Credits “Black cat” http://www.flickr.com/photos/revilla/529107119/
“Baseballs” http://www.flickr.com/photos/randomacts/2277808469/
“Basketball” http://www.flickr.com/photos/chillihead/3150447792/
“UNF Baseball vs. Florida Gulf Coast University” http://www.flickr.com/photos/8363028@N08/3368813471/
Licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License http://creativecommons.org/licenses/by-nc-sa/3.0/us/