functional fips: learning php for drupal theming
TRANSCRIPT
![Page 1: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/1.jpg)
Functional FIPSPHP for Drupal Designers and Themers
www.hicktech.com@emmajanedotnet
![Page 2: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/2.jpg)
About this talk● There are a lot of theme snippets available in the Theme Guide. There
is not, however, a lot of information about PHP which is the language that makes up these snippets. If you're tired of copying, pasting and praying and are ready to understand some of the magic behind those snippets, this session is for you!
● In this session you will learn how to manipulate and master:
● The very, very basics of PHP and the popular theming engine PHPtemplate
● Variables and tpl.php template files
● Arrays and objects and other crowbarworthy data containers.
● The really scary looking stuff that's in the mysterious file template.php
● Examples will be pulled from the Drupal.org Theme Guide as well as the wildly successful book on theming, Front End Drupal (coauthored by Emma Jane and Konstantin Kaefer).
![Page 3: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/3.jpg)
Stick around, I've got copies to give away.
![Page 4: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/4.jpg)
Drupal Theme Guidehttp://drupal.org/themeguide
![Page 5: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/5.jpg)
Theme snippetshttp://drupal.org/node/45471
![Page 6: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/6.jpg)
Learning through analogies
![Page 7: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/7.jpg)
www.travelinghoedowners.com
![Page 8: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/8.jpg)
bootstrappingbootstrapping
![Page 9: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/9.jpg)
http://www.jontwest.com/ProBono.php
VariablesVariables
![Page 10: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/10.jpg)
Variables
![Page 11: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/11.jpg)
Contents of variablesexist inside their containers
![Page 12: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/12.jpg)
Contents of variablesexist inside their containers
http://www.laboutiquedupetitprince.com/en/figures56/pixi81/pixifigurethelittleprincesheepbox518.html
![Page 13: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/13.jpg)
http://opswingers.free.fr/cestquoi.htm
RegionsRegions
![Page 14: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/14.jpg)
Regions
![Page 15: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/15.jpg)
http://www.dehnbase.org/sd/tutorial/counterrotate.php?p=4
FunctionsFunctions
![Page 16: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/16.jpg)
Functions
user_is_logged_in ()
user_access ('access administration pages')
in_array ('admin', array_values ($user>roles))
![Page 17: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/17.jpg)
ThemingTheminghttp://usawestwa.com/Outfit/
![Page 18: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/18.jpg)
www.squaredanceomaha.org/dress
ThemingTheming
![Page 19: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/19.jpg)
Decide on the danceChoose your clothes Dance the dance
http://www.kodakgallery.com/Slideshow.jsp?mode=fromshare&Uc=6m9np57.9mj7q0yf&Uy=ripni&Ux=0
PHPtemplatePHPtemplate
![Page 20: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/20.jpg)
PHPtemplate
Collect the content from Drupal using modules Run through the
Drupal theme functions & your
custom theme layer
Print the variables in your template
files
http://www.kodakgallery.com/Slideshow.jsp?mode=fromshare&Uc=6m9np57.9mj7q0yf&Uy=ripni&Ux=0
![Page 21: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/21.jpg)
How to create themes
1.Download an existing theme.
2.Look for variables and functions.
3.Alter the placement of the “printed” things.
4.Save and upload the theme files.
5.Clear the theme registry (Drupal admin).
6.Enjoy your new theme.
![Page 22: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/22.jpg)
page.tpl.php template file<!DOCTYPE html PUBLIC "//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="<?php print $language>language ?>" xml:lang="<?php print $language>language ?>"> <head> <title><?php print $head_title ?></title> <?php print $head ?> <?php print $styles ?> </head> <body> <div id="container"> <div id="header"> <div id="logoWrapper"> <?php if ($logo) { ?> <div id="logo"> <a href="<?php print $base_path ?>" title="<?php print t('Home') ?>"><img src="<?php print $logo ?>" alt="<?php print t('Home') ?>" /></a> </div><?php } ?>
![Page 23: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/23.jpg)
page.tpl.php template file<!DOCTYPE html PUBLIC "//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="<?php print $language>language ?>" xml:lang="<?php print $language>language ?>"> <head> <title><?php print $head_title ?></title> <?php print $head ?> <?php print $styles ?> </head> <body> <div id="container"> <div id="header"> <div id="logoWrapper"> <?php if ($logo) { ?> <div id="logo"> <a href="<?php print $base_path ?>" title="<?php print t('Home') ?>"><img src="<?php print $logo ?>" alt="<?php print t('Home') ?>" /></a> </div><?php } ?>
![Page 24: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/24.jpg)
Variables must be printed
<?php print ?>
![Page 25: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/25.jpg)
Variables must be printed
<title><?php print $head_title ?></title>
![Page 26: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/26.jpg)
Zomg what are those variables?
● Look at /modules/system/page.tpl.php
OR● http://api.drupal.org/api/drupal/modules
systempage.tpl.php/6
![Page 27: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/27.jpg)
page.tpl.php template file<!DOCTYPE html PUBLIC "//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="<?php print $language>language ?>" xml:lang="<?php print $language>language ?>"> <head> <title><?php print $head_title ?></title> <?php print $head ?> <?php print $styles ?> </head> <body> <div id="container"> <div id="header"> <div id="logoWrapper"> <?php if ($logo) { ?> <div id="logo"> <a href="<?php print $base_path ?>" title="<?php print t('Home') ?>"><img src="<?php print $logo ?>" alt="<?php print t('Home') ?>" /></a> </div><?php } ?>
![Page 28: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/28.jpg)
http://www.dehnbase.org/sd/tutorial/counterrotate.php?p=4
ConditionalsConditionalsif (you're the inside couple) {
go clockwise}
} else {go counter clockwise.
}
![Page 29: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/29.jpg)
What's an “if”?
if ($logo) {
<?php print ?>
}
![Page 30: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/30.jpg)
Fancy data structures: arrays + objectsGrouping and sorting your data
![Page 31: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/31.jpg)
Fancy data structures: arrays
Multiple values stored in one array
Multiple “drawers” of sorted content
![Page 32: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/32.jpg)
Devel Module: Themer Info
![Page 33: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/33.jpg)
$node object
$node>nid$node>body$node>content['body'][#value]
![Page 34: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/34.jpg)
“Advanced” PHP
● Never be afraid to try something.● Always back up your files first.● Take a LOT of notes.● Be bold! And be brave!
![Page 35: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/35.jpg)
template.php: what's up with that?
● Preparing variables that weren't assembled by Drupal and its modules.
● Altering the contents of variables that were prepared by Drupal and its modules.
● Special theming functions to do fun things like 'edit this block' links and random images.
● Read the Zen base theme documentation and template.php file.
![Page 36: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/36.jpg)
Using template.php
Collect the content from Drupal using modules and run it through the
default theme functions provided by Drupal.
Create new Create new information to feed information to feed
to your themeto your theme
Print the variables in your template
files
http://www.kodakgallery.com/Slideshow.jsp?mode=fromshare&Uc=6m9np57.9mj7q0yf&Uy=ripni&Ux=0
![Page 37: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/37.jpg)
PHP Snippetfrom: http://drupal.org/node/21401
<?php if ($submitted) { ?><span class="submitted"><?php if ($node>type == 'blog') { print 'Posted ' . format_date($node>created, 'custom', "F jS, Y") . ' by ' . theme('username', $node); } else { print 'By ' . theme('username', $node) . ' <br /> ' . format_date($node>created, 'custom', "F jS, Y") ; } ?></span><?php } ?>
![Page 38: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/38.jpg)
Summarizing PHP for Designers
● PHP is a linear “programming” language, just like a dance.
● PHP stores information in variables.● Sometimes variables hold lots of information
in special variables called “arrays.”● Drupal has lots of magic variables that are
loaded with content. Check out: http://drupal.org/themeguide
![Page 39: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/39.jpg)
ThemingTheminghttp://usawestwa.com/Outfit/
![Page 40: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/40.jpg)
http://www.jontwest.com/ProBono.php
VariablesVariables
![Page 41: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/41.jpg)
http://opswingers.free.fr/cestquoi.htm
RegionsRegions
![Page 42: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/42.jpg)
http://www.dehnbase.org/sd/tutorial/counterrotate.php?p=4
FunctionsFunctions
![Page 43: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/43.jpg)
http://www.dehnbase.org/sd/tutorial/counterrotate.php?p=4
ConditionalsConditionalsif (you're the inside couple) {
go clockwise}
} else {go counter clockwise.
}
![Page 44: Functional FIPS: Learning PHP for Drupal Theming](https://reader033.vdocument.in/reader033/viewer/2022052822/554c4bcbb4c905282a8b4589/html5/thumbnails/44.jpg)
Ready to rope Ready to rope yourself a yourself a theme?theme?
@[email protected] < theming classes < theming classesFront End Drupal < theming bookFront End Drupal < theming book
http://www.flickr.com/photos/fkehren/3352577815/