Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Drupal Theming 101

Drupal Theming 101

An introduction to Drupal theming given at the 2012 UT Austin DrupalCamp.

Avatar for Michael Caldwell

Michael Caldwell

May 31, 2012
Tweet

Other Decks in Technology

Transcript

  1. overrides intercepts template suggestions/candidates J argon wa tch themable functions

    & hooks When you’re starting out, all this boils down to…
  2. [drupal root] /includes /misc /modules /profiles /scripts /sites /themes /all

    /themes /theme101 Create your directory in /sites/all/themes
  3. name = Theme 101 description = Demo theme for UT

    Drupal Camp screenshot = screenshot.png core = 6.x engine = phptemplate stylesheets[all][] = css/style.css stylesheets[print][] = css/print.css regions[content_top] = Content top regions[header] = Header regions[left] = First sidebar regions[right] = Second sidebar regions[footer_block] = Footer regions[content_bottom] = Content bottom features[] = logo features[] = name … theme101.info Typical .info file, based on theBasic starter theme http://drupal.org/project/basic
  4. name = Theme 101 description = Demo theme for UT

    Drupal Camp screenshot = screenshot.png core = 6.x engine = phptemplate stylesheets[all][] = css/style.css stylesheets[print][] = css/print.css regions[content_top] = Content top regions[header] = Header regions[left] = First sidebar regions[right] = Second sidebar regions[footer_block] = Footer regions[content_bottom] = Content bottom features[] = logo features[] = name … theme101.info Settings for the theme admin UI
  5. name = Theme 101 description = Demo theme for UT

    Drupal Camp screenshot = screenshot.png core = 6.x engine = phptemplate stylesheets[all][] = css/style.css stylesheets[print][] = css/print.css regions[content_top] = Content top regions[header] = Header regions[left] = First sidebar regions[right] = Second sidebar regions[footer_block] = Footer regions[content_bottom] = Content bottom features[] = logo features[] = name … theme101.info Which version of Drupal the them is intended for
  6. name = Theme 101 description = Demo theme for UT

    Drupal Camp screenshot = screenshot.png core = 6.x engine = phptemplate stylesheets[all][] = css/style.css stylesheets[print][] = css/print.css regions[content_top] = Content top regions[header] = Header regions[left] = First sidebar regions[right] = Second sidebar regions[footer_block] = Footer regions[content_bottom] = Content bottom features[] = logo features[] = name … theme101.info Trust me.
  7. name = Theme 101 description = Demo theme for UT

    Drupal Camp screenshot = screenshot.png core = 6.x engine = phptemplate stylesheets[all][] = css/style.css stylesheets[print][] = css/print.css regions[content_top] = Content top regions[header] = Header regions[left] = First sidebar regions[right] = Second sidebar regions[footer_block] = Footer regions[content_bottom] = Content bottom features[] = logo features[] = name … theme101.info Define your styles. Note that you can use sub-directories for better organization
  8. … <link type="text/css" rel="stylesheet" media="all" href="/theming101/sites/all/themes/theme101/css/style.c ss" />… <link type="text/css"

    rel="stylesheet" media="print" href="/theming101/sites/all/themes/theme101/css/print.c ss" /> … theme101.info … stylesheets[all][] = css/style.css stylesheets[print][] = css/print.css … page.tpl.php
  9. name = Theme 101 description = Demo theme for UT

    Drupal Camp screenshot = screenshot.png core = 6.x engine = phptemplate stylesheets[all][] = css/style.css stylesheets[print][] = css/print.css regions[content_top] = Content top regions[header] = Header regions[left] = First sidebar regions[right] = Second sidebar regions[footer_block] = Footer regions[content_bottom] = Content bottom features[] = logo features[] = name … theme101.info Define your regions. Add/remove them later as needed.
  10. name = Theme 101 description = Demo theme for UT

    Drupal Camp screenshot = screenshot.png core = 6.x engine = phptemplate stylesheets[all][] = css/style.css stylesheets[print][] = css/print.css regions[content_top] = Content top regions[header] = Header regions[left] = First sidebar regions[right] = Second sidebar regions[footer_block] = Footer regions[content_bottom] = Content bottom features[] = logo features[] = name … theme101.info Settings for the theme config UI. Remove features your theme won’t support.
  11. … <?php if ($header): ?> <div id="header-region"> <?php print $header;

    ?> </div> <?php endif; ?> … page.tpl.php A typical PHP snippet you’ll see in template (.tpl.php) files
  12. … <?php if ($header): ?> <div id="header-region"> <?php print $header;

    ?> </div> <?php endif; ?> … page.tpl.php If there’s something in the header region …
  13. name = Theme 101 description = Demo theme for UT

    Drupal Camp screenshot = screenshot.png core = 6.x engine = phptemplate stylesheets[all][] = css/style.css stylesheets[print][] = css/print.css regions[content_top] = Content top regions[header] = Header regions[left] = First sidebar regions[right] = Second sidebar regions[footer_block] = Footer regions[content_bottom] = Content bottom features[] = logo features[] = name … theme101.info Notice how regions[header] here, has become $header in the .tpl.php file
  14. … <?php if ($header): ?> <div id="header-region"> <?php print $header;

    ?> </div> <?php endif; ?> … page.tpl.php Start by printing a wrapper div…
  15. … <?php if ($header): ?> <div id="header-region"> <?php print $header;

    ?> </div> <?php endif; ?> … page.tpl.php Output the contents of the region (usually one or more blocks) …
  16. … <?php if ($header): ?> <div id="header-region"> <?php print $header;

    ?> </div> <?php endif; ?> … page.tpl.php All done. If there was nothing in $header, none of this ever happened. Speak of it to no one.
  17. … <?php if ($header): ?> <div id="header-region" class="foo"> <?php print

    $header; ?> </div> <?php endif; ?> … page.tpl.php Add some arbitrary classname. It’s up to you.
  18. … <?php if ($header): ?> <div id="header-region" class="foo"> <div class="inner">

    <?php print $header; ?> </div> </div> <?php endif; ?> … page.tpl.php Need some additional html? Throw it in there. Just be careful not to disturb the php tags until you know what you (and they) are doing.
  19. … <?php if ($header): ?> <div id="header-region" class="foo"> <div class="inner">

    <?php print $header; ?> </div> </div> <?php endif; ?> … page.tpl.php
  20. Tools & Resources Drupal Modules Admin Menu – http://drupal.org/project/admin_menu Devel

    – http://drupal.org/project/devel Theme Developer – http://drupal.org/project/devel_themer Brower Tools Firebug – http://getfirebug.com Web Dev Toolbar - http://chrispederick.com/work/web-developer/ Popular, High Quality Starter Themes Basic - http://drupal.org/project/basic Omega - http://drupal.org/project/omega Zen - http://drupal.org/project/zen