Introduction to
Theme Preprocess
Functions


BADCamp
18 Oct 2009

Carl Wiedemann
drupal.org user c4rl
Preprocess in
   Theory
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 theme content?
<div class="<?php print $my_classes; ?>">
     <?php print $my_content; ?>
</div>



   How can we create more useful them...
Preprocess
<?php print $my_content; ?>



   Preprocess
  makes content
     flexible
class="<?php print $my_classes; ?>"



      Preprocess
     makes theming
       dynamic
if else foreach while switch =



    Preprocess
  keeps templates
       clean
So, when does
preprocess happen?
Request
   Processing
Database
           Raw Data

                          Modules
Request
   Processing


           Return Data
Database
           Raw Data

                             Modules
Request
   Processing


           Return Data

       ...
Database
           Raw Data

                             Modules
Request
   Processing


           Return Data

       ...
Preprocess in
  Practice
Firebug
Web Developer Toolbar

    admin_menu
        devel
    devel_themer
Exploring
      template.php
mytheme_preprocess_page
           dsm
mytheme_preprocess_node
        theme.inc
         Demo
Manually creating
   $myvar
 $submitted

       Demo
Specifying additional
     templates


        Demo
Contextual CSS




     Demo
Working with CCK
  $content


      Demo
Important things to
      remember:
   dsm() delays on preprocess_page()

Clear cache when adding new tpl files and adding
...
Questions and
Thanks
Thanks to Matt Tucker (ultimateboy) for inspiring this talk

Demo Photography Credits
 “Black cat”
 h...
Upcoming SlideShare
Loading in …5
×

Introduction to Theme Preprocess Functions

2,099
-1

Published on

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,099
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
20
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Introduction to Theme Preprocess Functions

  1. 1. Introduction to Theme Preprocess Functions BADCamp 18 Oct 2009 Carl Wiedemann drupal.org user c4rl
  2. 2. Preprocess in Theory
  3. 3. Theme Dilemmas
  4. 4. <div class="content"> <?php print $content; ?> </div> What do we do if this is insufficient?
  5. 5. <div class="content"> <?php print $my_content; ?> </div> How can we create more useful theme content?
  6. 6. <div class="<?php print $my_classes; ?>"> <?php print $my_content; ?> </div> How can we create more useful theme content? How can we keep our theme contextual?
  7. 7. Preprocess
  8. 8. <?php print $my_content; ?> Preprocess makes content flexible
  9. 9. class="<?php print $my_classes; ?>" Preprocess makes theming dynamic
  10. 10. if else foreach while switch = Preprocess keeps templates clean
  11. 11. So, when does preprocess happen?
  12. 12. Request Processing
  13. 13. Database Raw Data Modules Request Processing Return Data
  14. 14. Database Raw Data Modules Request Processing Return Data Theme Formatted Data HTML!
  15. 15. Database Raw Data Modules Request Processing Return Data Theme Formatted Data HTML!
  16. 16. Preprocess in Practice
  17. 17. Firebug Web Developer Toolbar admin_menu devel devel_themer
  18. 18. Exploring template.php mytheme_preprocess_page dsm mytheme_preprocess_node theme.inc Demo
  19. 19. Manually creating $myvar $submitted Demo
  20. 20. Specifying additional templates Demo
  21. 21. Contextual CSS Demo
  22. 22. Working with CCK $content Demo
  23. 23. 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
  24. 24. 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/
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×