introduction to theme preprocess functions

24
Introduction to Theme Preprocess Functions BADCamp 18 Oct 2009 Carl Wiedemann drupal.org user c4rl

Upload: c4rl

Post on 07-Dec-2014

3.280 views

Category:

Technology


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Introduction to Theme Preprocess Functions

Introduction to Theme Preprocess Functions

BADCamp 18 Oct 2009

Carl Wiedemann drupal.org user c4rl

Page 2: Introduction to Theme Preprocess Functions

Preprocess in Theory

Page 3: Introduction to Theme Preprocess Functions

Theme Dilemmas

Page 4: Introduction to Theme Preprocess Functions

What do we do if this is insufficient?

<div class="content"> <?php print $content; ?> </div>

Page 5: Introduction to Theme Preprocess Functions

How can we create more useful theme content?

<div class="content"> <?php print $my_content; ?> </div>

Page 6: Introduction to Theme Preprocess Functions

<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?

Page 7: Introduction to Theme Preprocess Functions

Preprocess

Page 8: Introduction to Theme Preprocess Functions

Preprocess makes content

flexible

<?php print $my_content; ?>

Page 9: Introduction to Theme Preprocess Functions

Preprocess makes theming

dynamic

class="<?php print $my_classes; ?>"

Page 10: Introduction to Theme Preprocess Functions

Preprocess keeps templates

clean

if else foreach while switch =

Page 11: Introduction to Theme Preprocess Functions

So, when does preprocess happen?

Page 12: Introduction to Theme Preprocess Functions

Processing Request

Page 13: Introduction to Theme Preprocess Functions

Raw Data

Processing

Return Data

Database

Modules Request

Page 14: Introduction to Theme Preprocess Functions

Raw Data

Processing

Return Data

Formatted Data

HTML!

Database

Modules

Theme

Request

Page 15: Introduction to Theme Preprocess Functions

Raw Data

Processing

Return Data

Formatted Data

HTML!

Database

Modules

Theme

Request

Page 16: Introduction to Theme Preprocess Functions

Preprocess in Practice

Page 17: Introduction to Theme Preprocess Functions

Firebug Web Developer Toolbar

admin_menu devel

devel_themer

Page 18: Introduction to Theme Preprocess Functions

Demo

template.php mytheme_preprocess_page

dsm mytheme_preprocess_node

theme.inc

Exploring

Page 19: Introduction to Theme Preprocess Functions

Demo

Manually creating $myvar

$submitted

Page 20: Introduction to Theme Preprocess Functions

Demo

Specifying additional templates

Page 21: Introduction to Theme Preprocess Functions

Demo

Contextual CSS

Page 22: Introduction to Theme Preprocess Functions

Demo

Working with CCK $content

Page 23: Introduction to Theme Preprocess Functions

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

Page 24: Introduction to Theme Preprocess Functions

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/