Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Theme preprocessfunctions: anintroductionDrupalCampNYCDecember 10th, 2011
Carl Wiedemann
Carl Wiedemann           t  I live here in NYC...
Carl Wiedemann ...originally from Denver
RIP
c4rl...on various channels
Preprocess in   Theory
7!          7!Theme Dilemmas
<div class="content">     <?php print $content; ?></div>     What do we do if this is insufficient?
<div class="content">     <?php print $my_content; ?></div>   How can we create more useful content?
<div class="<?php print $my_classes; ?>">     <?php print $my_content; ?></div>   How can we create more useful content?  ...
Preprocess
<?php print $my_content; ?> Preprocessmakes content   flexible
class="<?php print $my_classes; ?>"     Preprocess    makes theming      dynamic
if else foreach while switch =  Preprocesskeeps templates     clean
So, when does preprocess   happen?
Request   ...Server receives request
Database          Raw data                        ModulesRequest   Processing          Return data
Database          Raw data                           ModulesRequest   Processing          Return data                     ...
Database          Raw data                           ModulesRequest   Processing          Return data                     ...
Database          Raw data                           ModulesRequest   Processing          Return data                     ...
Preprocess in  Practice
Firebug (or similar)     devel     drush
Exploring          includes/theme.incsites/all/themes/jupiter/template.php    jupiter_preprocess_page()           dpm() dd...
Manually creating  $submitted    $myvar       Demo
Specifying additional     templates         Demo
Contextual CSS     Demo
Working with CCK                 7!                 7!Working with fields        Demo
Every template has a   preprocessor!      Dont forget :)
file-name.tpl.phpjupiter_preprocess_file_name()         Dont forget :)
Sexier examples     Oh yeah
Views inbox    Demo
Cheap JSON API     Demo
Disclaimer :)
Important things to    remember:             dpm() delays         Dont overload dpm()!Clear cache when adding new tpl file...
Questions?Anyone? Anyone?
ThanksThanks to Matt Tucker (ultimateboy) for inspiring this talkDemo Photography Credits"Baseballs"http://www.flickr.com/...
Theme preprocessfunctions: anintroductionDrupalCampNYCDecember 10th, 2011
Theme preprocess functions: An Introduction (DrupalCamp NYC 10 2011)
Theme preprocess functions: An Introduction (DrupalCamp NYC 10 2011)
Theme preprocess functions: An Introduction (DrupalCamp NYC 10 2011)
Theme preprocess functions: An Introduction (DrupalCamp NYC 10 2011)
Upcoming SlideShare
Loading in …5
×

Theme preprocess functions: An Introduction (DrupalCamp NYC 10 2011)

2,939 views

Published on

Slides from http://drupalcampnyc.org/sessions/theme-preprocess-functions-introduction

Published in: Technology, Sports
  • Be the first to comment

  • Be the first to like this

Theme preprocess functions: An Introduction (DrupalCamp NYC 10 2011)

  1. 1. Theme preprocessfunctions: anintroductionDrupalCampNYCDecember 10th, 2011
  2. 2. Carl Wiedemann
  3. 3. Carl Wiedemann t I live here in NYC...
  4. 4. Carl Wiedemann ...originally from Denver
  5. 5. RIP
  6. 6. c4rl...on various channels
  7. 7. Preprocess in Theory
  8. 8. 7! 7!Theme Dilemmas
  9. 9. <div class="content"> <?php print $content; ?></div> What do we do if this is insufficient?
  10. 10. <div class="content"> <?php print $my_content; ?></div> How can we create more useful content?
  11. 11. <div class="<?php print $my_classes; ?>"> <?php print $my_content; ?></div> How can we create more useful content? How can we keep our theme contextual?
  12. 12. Preprocess
  13. 13. <?php print $my_content; ?> Preprocessmakes content flexible
  14. 14. class="<?php print $my_classes; ?>" Preprocess makes theming dynamic
  15. 15. if else foreach while switch = Preprocesskeeps templates clean
  16. 16. So, when does preprocess happen?
  17. 17. Request ...Server receives request
  18. 18. Database Raw data ModulesRequest Processing Return data
  19. 19. Database Raw data ModulesRequest Processing Return data Theme Formatted data HTML!
  20. 20. Database Raw data ModulesRequest Processing Return data Theme Formatted data HTML!
  21. 21. Database Raw data ModulesRequest Processing Return data Theme Formatted data HTML!
  22. 22. Preprocess in Practice
  23. 23. Firebug (or similar) devel drush
  24. 24. Exploring includes/theme.incsites/all/themes/jupiter/template.php jupiter_preprocess_page() dpm() dd() jupiter_preprocess_node() Demo
  25. 25. Manually creating $submitted $myvar Demo
  26. 26. Specifying additional templates Demo
  27. 27. Contextual CSS Demo
  28. 28. Working with CCK 7! 7!Working with fields Demo
  29. 29. Every template has a preprocessor! Dont forget :)
  30. 30. file-name.tpl.phpjupiter_preprocess_file_name() Dont forget :)
  31. 31. Sexier examples Oh yeah
  32. 32. Views inbox Demo
  33. 33. Cheap JSON API Demo
  34. 34. Disclaimer :)
  35. 35. Important things to remember: dpm() delays Dont overload dpm()!Clear cache when adding new tpl files and adding functions to template.phpUse check_markup() and check_plain() on data that may be unsafe
  36. 36. Questions?Anyone? Anyone?
  37. 37. ThanksThanks to Matt Tucker (ultimateboy) for inspiring this talkDemo Photography Credits"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/"Thor vs. Superman (49/365)"http://www.flickr.com/photos/jdhancock/4369073183/ Licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License http://creativecommons.org/licenses/by-nc-sa/3.0/us/
  38. 38. Theme preprocessfunctions: anintroductionDrupalCampNYCDecember 10th, 2011

×