99
!"#$ &"'()* +,-./01 !"#$" &'() *+,-. /$0"120 34"#$"5 67$(89:9

Grok Drupal (7) Theming

  • Upload
    pingv

  • View
    63.136

  • Download
    2

Embed Size (px)

DESCRIPTION

These are slides from Laura Scott's DrupalCon San Francisco presentation on Drupal theming. (There's a video of it at that link as well.)

Citation preview

Page 1: Grok Drupal (7) Theming

!"#$%&"'()*%+,-./01!"#$"%&'()*+,-.%/$0"120

34"#$"5 67$(89:9

Page 2: Grok Drupal (7) Theming

9$#;"4<($7=#50$=>?@AB

!"#$"%&'()/$0"120%CD$0'E(

$F%C$#;"4%G$'HDE0'E%

"I9%/(JK(#I90$

*+,-.%/$0"120

34"#$"5

C$#;"4%5DI'0%LMM:

67$(89:9

Page 4: Grok Drupal (7) Theming

More on Drupal Theming this week

• Theming with Skinr! (Jacine Rodriguez) — Right after this session, right here in this room.

• All your html are belong to us (Morten) — Wednesday at 4:15pm.

• Sprint on Thursday — Free! Open! Friendly!

Page 5: Grok Drupal (7) Theming

!"#$%&"'()*%+,-./01

Grok means to understand so thoroughly that the observer becomes a part of the observed — to merge, blend, intermarry,

lose identity in group experience.

Robert A. Heinlein, Stranger in a Strange Land

Page 6: Grok Drupal (7) Theming

!"#$%&"'()*%+,-./01<h1 id="title"> </h1>

Page 7: Grok Drupal (7) Theming

!"#$%&"'()*%+,-./01<h1 id="title"> </h1>

How Drupal displays content (templates)

How to start theming

Other things to consider

Page 8: Grok Drupal (7) Theming

Assumptions

• You know HTML/xhtml

• You know CSS 2.1

• You are at least getting to know CSS 3 (or want to)

• Drupal theming confuses or mystifies you

• You don't know PHP(but if you do, we won't hold it against you)

• You understand some basic Drupal architecture concepts

• You want to learn this

Page 9: Grok Drupal (7) Theming

Some PHP required

• Mainly to print pre-defined variables … e.g., $title (for the page title).

• You can do a lot in the "preprocess" and "process" functions.

• You can avoid it if it totally scares the living daylights out of you. Just stick to copy and paste from '<?php' to '?>'.

Page 10: Grok Drupal (7) Theming

Drupal 7 is more complex than Drupal 6

...but it's also more simple

Page 11: Grok Drupal (7) Theming

Anatomy of a Drupal "page"

• xhtml, CSS, images

• Content presented via templates

• JavaScript

Page 12: Grok Drupal (7) Theming

The Drupal theme

• CSS files

• Image files

• Template files

• JavaScript files

• Preprocess and process files

• .info file

new!

Page 13: Grok Drupal (7) Theming

Which template?

It depends....

Page 14: Grok Drupal (7) Theming
Page 15: Grok Drupal (7) Theming
Page 16: Grok Drupal (7) Theming
Page 17: Grok Drupal (7) Theming
Page 18: Grok Drupal (7) Theming
Page 19: Grok Drupal (7) Theming
Page 20: Grok Drupal (7) Theming

Every module's output also has a template file.

(In theory.)

Page 21: Grok Drupal (7) Theming

42 *.tpl.php files in D7's /modules folder.

Each can be copied and used to override.

Page 22: Grok Drupal (7) Theming

One theme might have dozens of

template files.

Page 23: Grok Drupal (7) Theming
Page 24: Grok Drupal (7) Theming

There are only a few basics.

(It's not rocket science.)

Page 25: Grok Drupal (7) Theming

What's inside a template?

Page 26: Grok Drupal (7) Theming

html.tpl.php

Page 27: Grok Drupal (7) Theming

html.tpl.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print $language->language; ?>" version="XHTML+RDFa 1.0" dir="<?php print $language->dir; ?>" <?php print $rdf_namespaces; ?>>

Page 28: Grok Drupal (7) Theming

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print $language->language; ?>" version="XHTML+RDFa 1.0" dir="<?php print $language->dir; ?>" <?php print $rdf_namespaces; ?>>

<head profile="<?php print $grddl_profile; ?>"> <?php print $head; ?> <title><?php print $head_title; ?></title> <?php print $styles; ?> <?php print $scripts; ?></head>

html.tpl.php

Page 29: Grok Drupal (7) Theming

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print $language->language; ?>" version="XHTML+RDFa 1.0" dir="<?php print $language->dir; ?>" <?php print $rdf_namespaces; ?>>

<head profile="<?php print $grddl_profile; ?>"> <?php print $head; ?> <title><?php print $head_title; ?></title> <?php print $styles; ?> <?php print $scripts; ?></head>

<body class="<?php print $classes; ?>" <?php print $attributes;?>> <div id="skip-link"> <a href="#main-content"><?php print t('Skip to main content'); ?></a> </div> <?php print $page_top; ?> <?php print $page; ?> <?php print $page_bottom; ?></body></html>

html.tpl.php

Page 30: Grok Drupal (7) Theming

<body class="<?php print $classes; ?>" <?php print $attributes;?>> <div id="skip-link"> <a href="#main-content"><?php print t('Skip to main content'); ?></a> </div> <?php print $page_top; ?> <?php print $page; ?> <?php print $page_bottom; ?></body></html>

Page 31: Grok Drupal (7) Theming

<body class="<?php print $classes; ?>" <?php print $attributes;?>> <div id="skip-link"> <a href="#main-content"><?php print t('Skip to main content'); ?></a> </div> <?php print $page_top; ?> <?php print $page; ?> <?php print $page_bottom; ?></body></html>

Page 32: Grok Drupal (7) Theming

page.tpl.php

Page 33: Grok Drupal (7) Theming

page.tpl.php <div id="page-wrapper"><div id="page">

<div id="header"><div class="section clearfix">

<?php if ($logo): ?> <a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" rel="home" id="logo"> <img src="<?php print $logo; ?>" alt="<?php print t('Home'); ?>" /> </a> <?php endif; ?>

<?php if ($site_name || $site_slogan): ?> <div id="name-and-slogan"> <?php if ($site_name): ?> <?php if ($title): ?> <div id="site-name"><strong> <a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" rel="home"><span><?php print $site_name; ?></span></a> </strong></div> <?php else: /* Use h1 when the content title is empty */ ?> <h1 id="site-name"> <a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" rel="home"><span><?php print $site_name; ?></span></a> </h1> <?php endif; ?> <?php endif; ?>

<?php if ($site_slogan): ?> <div id="site-slogan"><?php print $site_slogan; ?></div> <?php endif; ?> </div> <!-- /#name-and-slogan --> <?php endif; ?>

<?php print render($page['header']); ?>

</div></div> <!-- /.section, /#header -->

<?php if ($main_menu): ?> <div id="navigation"><div class="section"> <?php print theme('links__system_main_menu', array('links' => $main_menu, 'attributes' => array('id' => 'main-menu', 'class' => array('links', 'clearfix')), 'heading' => t('Main menu'))); ?> </div></div> <!-- /.section, /#navigation --> <?php endif; ?>

<?php if ($breadcrumb): ?> <div id="breadcrumb"><?php print $breadcrumb; ?></div> <?php endif; ?>

<?php print $messages; ?>

<div id="main-wrapper"><div id="main" class="clearfix">

<div id="content" class="column"><div class="section"> <?php if ($page['highlight']): ?><div id="highlight"><?php print render($page['highlight']); ?></div><?php endif; ?> <a id="main-content"></a> <?php print render($title_prefix); ?> <?php if ($title): ?><h1 class="title" id="page-title"><?php print $title; ?></h1><?php endif; ?> <?php print render($title_suffix); ?> <?php if ($tabs): ?><div class="tabs"><?php print render($tabs); ?></div><?php endif; ?> <?php print render($page['help']); ?> <?php if ($action_links): ?><ul class="action-links"><?php print render($action_links); ?></ul><?php endif; ?> <?php print render($page['content']); ?> <?php print $feed_icons; ?> </div></div> <!-- /.section, /#content -->

<?php if ($page['sidebar_first']): ?> <div id="sidebar-first" class="column sidebar"><div class="section"> <?php print render($page['sidebar_first']); ?> </div></div> <!-- /.section, /#sidebar-first --> <?php endif; ?>

<?php if ($page['sidebar_second']): ?> <div id="sidebar-second" class="column sidebar"><div class="section"> <?php print render($page['sidebar_second']); ?> </div></div> <!-- /.section, /#sidebar-second --> <?php endif; ?>

</div></div> <!-- /#main, /#main-wrapper -->

<div id="footer"><div class="section"> <?php print theme('links__system_secondary_menu', array('links' => $secondary_menu, 'attributes' => array('id' => 'secondary-menu', 'class' => array('links', 'clearfix')), 'heading' => t('Secondary menu'))); ?> <?php print render($page['footer']); ?> </div></div> <!-- /.section, /#footer -->

</div></div> <!-- /#page, /#page-wrapper -->

logosite namesite sloganmain menubreadcrumb

messages

highight<h1> title

tabshelp

content

sidebarsfooter

sidebarsfeed icons

Page 34: Grok Drupal (7) Theming

The Semantic Page

• Logo/branding/site name

• [main nav]*

• <h1> Title (of article, view, blog post, etc.)

• Main content

• Then sidebar(s), footer

* and that's debated

Page 35: Grok Drupal (7) Theming

<div id="page-wrapper"><div id="page">

<div id="header"><div class="section clearfix">

<?php if ($logo): ?> <a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" rel="home" id="logo"> <img src="<?php print $logo; ?>" alt="<?php print t('Home'); ?>" /> </a> <?php endif; ?>

<?php if ($site_name || $site_slogan): ?> <div id="name-and-slogan"> <?php if ($site_name): ?> <?php if ($title): ?> <div id="site-name"><strong> <a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" rel="home"><span><?php print $site_name; ?></span></a> </strong></div> <?php else: /* Use h1 when the content title is empty */ ?> <h1 id="site-name"> <a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" rel="home"><span><?php print $site_name; ?></span></a> </h1> <?php endif; ?> <?php endif; ?>

<?php if ($site_slogan): ?> <div id="site-slogan"><?php print $site_slogan; ?></div> <?php endif; ?> </div> <!-- /#name-and-slogan --> <?php endif; ?>

<?php print render($page['header']); ?>

</div></div> <!-- /.section, /#header -->

page.tpl.php

<?php if ($main_menu): ?> <div id="navigation"><div class="section"> <?php print theme('links__system_main_menu', array('links' => $main_menu, 'attributes' => array('id' => 'main-menu', 'class' => array('links', 'clearfix')), 'heading' => t('Main menu'))); ?> </div></div> <!-- /.section, /#navigation --> <?php endif; ?>

<?php if ($breadcrumb): ?> <div id="breadcrumb"><?php print $breadcrumb; ?></div> <?php endif; ?>

<?php print $messages; ?> <div id="main-wrapper"><div id="main" class="clearfix"> <div id="content" class="column"><div class="section"> <?php if ($page['highlight']): ?><div id="highlight"><?php print render($page['highlight']); ?></div><?php endif; ?> <a id="main-content"></a> <?php print render($title_prefix); ?> <?php if ($title): ?><h1 class="title" id="page-title"><?php print $title; ?></h1><?php endif; ?> <?php print render($title_suffix); ?> <?php if ($tabs): ?><div class="tabs"><?php print render($tabs); ?></div><?php endif; ?> <?php print render($page['help']); ?> <?php if ($action_links): ?><ul class="action-links"><?php print render($action_links); ?></ul><?php endif; ?> <?php print render($page['content']); ?> <?php print $feed_icons; ?> </div></div> <!-- /.section, /#content --> <?php if ($page['sidebar_first']): ?> <div id="sidebar-first" class="column sidebar"><div class="section"> <?php print render($page['sidebar_first']); ?> </div></div> <!-- /.section, /#sidebar-first --> <?php endif; ?> <?php if ($page['sidebar_second']): ?> <div id="sidebar-second" class="column sidebar"><div class="section"> <?php print render($page['sidebar_second']); ?> </div></div> <!-- /.section, /#sidebar-second --> <?php endif; ?> </div></div> <!-- /#main, /#main-wrapper -->

<div id="footer"><div class="section"> <?php print theme('links__system_secondary_menu', array('links' => $secondary_menu, 'attributes' => array('id' => 'secondary-menu', 'class' => array('links', 'clearfix')), 'heading' => t('Secondary menu'))); ?> <?php print render($page['footer']); ?> </div></div> <!-- /.section, /#footer -->

</div></div> <!-- /#page, /#page-wrapper -->

Page 36: Grok Drupal (7) Theming

<div id="page-wrapper"><div id="page">

<div id="header"><div class="section clearfix">

<?php if ($logo): ?> <a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" rel="home" id="logo"> <img src="<?php print $logo; ?>" alt="<?php print t('Home'); ?>" /> </a> <?php endif; ?>

<?php if ($site_name || $site_slogan): ?> <div id="name-and-slogan"> <?php if ($site_name): ?> <?php if ($title): ?> <div id="site-name"><strong> <a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" rel="home"><span><?php print $site_name; ?></span></a> </strong></div> <?php else: /* Use h1 when the content title is empty */ ?> <h1 id="site-name"> <a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" rel="home"><span><?php print $site_name; ?></span></a> </h1> <?php endif; ?> <?php endif; ?>

<?php if ($site_slogan): ?> <div id="site-slogan"><?php print $site_slogan; ?></div> <?php endif; ?> </div> <!-- /#name-and-slogan --> <?php endif; ?>

<?php print render($page['header']); ?>

</div></div> <!-- /.section, /#header -->

page.tpl.php

<?php if ($main_menu): ?> <div id="navigation"><div class="section"> <?php print theme('links__system_main_menu', array('links' => $main_menu, 'attributes' => array('id' => 'main-menu', 'class' => array('links', 'clearfix')), 'heading' => t('Main menu'))); ?> </div></div> <!-- /.section, /#navigation --> <?php endif; ?>

<?php if ($breadcrumb): ?> <div id="breadcrumb"><?php print $breadcrumb; ?></div> <?php endif; ?>

<?php print $messages; ?> <div id="main-wrapper"><div id="main" class="clearfix"> <div id="content" class="column"><div class="section"> <?php if ($page['highlight']): ?><div id="highlight"><?php print render($page['highlight']); ?></div><?php endif; ?> <a id="main-content"></a> <?php print render($title_prefix); ?> <?php if ($title): ?><h1 class="title" id="page-title"><?php print $title; ?></h1><?php endif; ?> <?php print render($title_suffix); ?> <?php if ($tabs): ?><div class="tabs"><?php print render($tabs); ?></div><?php endif; ?> <?php print render($page['help']); ?> <?php if ($action_links): ?><ul class="action-links"><?php print render($action_links); ?></ul><?php endif; ?> <?php print render($page['content']); ?> <?php print $feed_icons; ?> </div></div> <!-- /.section, /#content --> <?php if ($page['sidebar_first']): ?> <div id="sidebar-first" class="column sidebar"><div class="section"> <?php print render($page['sidebar_first']); ?> </div></div> <!-- /.section, /#sidebar-first --> <?php endif; ?> <?php if ($page['sidebar_second']): ?> <div id="sidebar-second" class="column sidebar"><div class="section"> <?php print render($page['sidebar_second']); ?> </div></div> <!-- /.section, /#sidebar-second --> <?php endif; ?> </div></div> <!-- /#main, /#main-wrapper -->

<div id="footer"><div class="section"> <?php print theme('links__system_secondary_menu', array('links' => $secondary_menu, 'attributes' => array('id' => 'secondary-menu', 'class' => array('links', 'clearfix')), 'heading' => t('Secondary menu'))); ?> <?php print render($page['footer']); ?> </div></div> <!-- /.section, /#footer -->

</div></div> <!-- /#page, /#page-wrapper -->

Page 37: Grok Drupal (7) Theming

<div id="page-wrapper"><div id="page">

<div id="header"><div class="section clearfix">

<?php if ($logo): ?> <a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" rel="home" id="logo"> <img src="<?php print $logo; ?>" alt="<?php print t('Home'); ?>" /> </a> <?php endif; ?>

<?php if ($site_name || $site_slogan): ?> <div id="name-and-slogan"> <?php if ($site_name): ?> <?php if ($title): ?> <div id="site-name"><strong> <a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" rel="home"><span><?php print $site_name; ?></span></a> </strong></div> <?php else: /* Use h1 when the content title is empty */ ?> <h1 id="site-name"> <a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" rel="home"><span><?php print $site_name; ?></span></a> </h1> <?php endif; ?> <?php endif; ?>

<?php if ($site_slogan): ?> <div id="site-slogan"><?php print $site_slogan; ?></div> <?php endif; ?> </div> <!-- /#name-and-slogan --> <?php endif; ?>

<?php print render($page['header']); ?>

</div></div> <!-- /.section, /#header -->

page.tpl.php

<?php if ($main_menu): ?> <div id="navigation"><div class="section"> <?php print theme('links__system_main_menu', array('links' => $main_menu, 'attributes' => array('id' => 'main-menu', 'class' => array('links', 'clearfix')), 'heading' => t('Main menu'))); ?> </div></div> <!-- /.section, /#navigation --> <?php endif; ?>

<?php if ($breadcrumb): ?> <div id="breadcrumb"><?php print $breadcrumb; ?></div> <?php endif; ?>

<?php print $messages; ?> <div id="main-wrapper"><div id="main" class="clearfix"> <div id="content" class="column"><div class="section"> <?php if ($page['highlight']): ?><div id="highlight"><?php print render($page['highlight']); ?></div><?php endif; ?> <a id="main-content"></a> <?php print render($title_prefix); ?> <?php if ($title): ?><h1 class="title" id="page-title"><?php print $title; ?></h1><?php endif; ?> <?php print render($title_suffix); ?> <?php if ($tabs): ?><div class="tabs"><?php print render($tabs); ?></div><?php endif; ?> <?php print render($page['help']); ?> <?php if ($action_links): ?><ul class="action-links"><?php print render($action_links); ?></ul><?php endif; ?> <?php print render($page['content']); ?> <?php print $feed_icons; ?> </div></div> <!-- /.section, /#content --> <?php if ($page['sidebar_first']): ?> <div id="sidebar-first" class="column sidebar"><div class="section"> <?php print render($page['sidebar_first']); ?> </div></div> <!-- /.section, /#sidebar-first --> <?php endif; ?> <?php if ($page['sidebar_second']): ?> <div id="sidebar-second" class="column sidebar"><div class="section"> <?php print render($page['sidebar_second']); ?> </div></div> <!-- /.section, /#sidebar-second --> <?php endif; ?> </div></div> <!-- /#main, /#main-wrapper -->

<div id="footer"><div class="section"> <?php print theme('links__system_secondary_menu', array('links' => $secondary_menu, 'attributes' => array('id' => 'secondary-menu', 'class' => array('links', 'clearfix')), 'heading' => t('Secondary menu'))); ?> <?php print render($page['footer']); ?> </div></div> <!-- /.section, /#footer -->

</div></div> <!-- /#page, /#page-wrapper -->

Page 38: Grok Drupal (7) Theming

node.tpl.php

Page 39: Grok Drupal (7) Theming

node.tpl.php

<div id="node-<?php print $node->nid; ?>" class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>

<?php print $user_picture; ?>

<?php print render($title_prefix); ?> <?php if (!$page): ?> <h2<?php print $title_attributes; ?>><a href="<?php print $node_url; ?>"><?php print $title; ?></a></h2> <?php endif; ?> <?php print render($title_suffix); ?>

<?php if ($display_submitted): ?> <div class="submitted"> <?php print t('Submitted by !username on !datetime', array('!username' => $name, '!datetime' => $date)); ?> </div> <?php endif; ?>

<div class="content"<?php print $content_attributes; ?>> <?php // We hide the comments and links now so that we can render them later. hide($content['comments']); hide($content['links']); print render($content); ?> </div>

<?php print render($content['links']); ?>

<?php print render($content['comments']); ?>

</div>

Page 40: Grok Drupal (7) Theming

node.tpl.php

<div id="node-<?php print $node->nid; ?>" class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>

<?php print $user_picture; ?>

<?php print render($title_prefix); ?> <?php if (!$page): ?> <h2<?php print $title_attributes; ?>><a href="<?php print $node_url; ?>"><?php print $title; ?></a></h2> <?php endif; ?> <?php print render($title_suffix); ?>

<?php if ($display_submitted): ?> <div class="submitted"> <?php print t('Submitted by !username on !datetime', array('!username' => $name, '!datetime' => $date)); ?> </div> <?php endif; ?>

<div class="content"<?php print $content_attributes; ?>> <?php // We hide the comments and links now so that we can render them later. hide($content['comments']); hide($content['links']); print render($content); ?> </div>

<?php print render($content['links']); ?>

<?php print render($content['comments']); ?>

</div>

new!

Page 41: Grok Drupal (7) Theming

block.tpl.php

Page 42: Grok Drupal (7) Theming

block.tpl.php

<div id="block-<?php print $block->module . '-' . $block->delta; ?>" class="<?php print $classes; ?>"<?php print $attributes; ?>>

<?php print render($title_prefix); ?><?php if ($block->subject): ?> <h2<?php print $title_attributes; ?>><?php print $block->subject ?></h2><?php endif;?> <?php print render($title_suffix); ?>

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

Page 43: Grok Drupal (7) Theming

block.tpl.php

<div id="block-<?php print $block->module . '-' . $block->delta; ?>" class="<?php print $classes; ?>"<?php print $attributes; ?>>

<?php print render($title_prefix); ?><?php if ($block->subject): ?> <h2<?php print $title_attributes; ?>><?php print $block->subject ?></h2><?php endif;?> <?php print render($title_suffix); ?>

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

Page 44: Grok Drupal (7) Theming

comment-wrapper.tpl.php

Page 45: Grok Drupal (7) Theming

comment-wrapper.tpl.php

<div id="comments" class="<?php print $classes; ?>"<?php print $attributes; ?>> <?php if ($content['comments'] && $node->type != 'forum'): ?> <h2 class="title"><?php print t('Comments'); ?></h2> <?php endif; ?>

<?php print render($content['comments']); ?>

<?php if ($content['comment_form']): ?> <h2 class="title comment-form"><?php print t('Add new comment'); ?></h2> <?php print render($content['comment_form']); ?> <?php endif; ?></div>

Page 46: Grok Drupal (7) Theming

comment.tpl.php

Page 47: Grok Drupal (7) Theming

comment.tpl.php

<div class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>> <?php print $picture ?>

<?php if ($new): ?> <span class="new"><?php print $new ?></span> <?php endif; ?>

<?php print render($title_prefix); ?> <h3<?php print $title_attributes; ?>><?php print $title ?></h3> <?php print render($title_suffix); ?>

<div class="submitted"> <?php print $permalink; ?> <?php print t('Submitted by !username on !datetime.', array('!username' => $author, '!datetime' => $created)); ?> </div>

<div class="content"<?php print $content_attributes; ?>> <?php // We hide the comments and links now so that we can render them later. hide($content['links']); print render($content); ?> <?php if ($signature): ?> <div class="user-signature clearfix"> <?php print $signature ?> </div> <?php endif; ?> </div>

<?php print render($content['links']) ?></div>

Page 48: Grok Drupal (7) Theming

polls

Page 49: Grok Drupal (7) Theming

node.tpl.php node.tpl.php

poll-vote.tpl.php poll-results.tpl.php

poll-bar.tpl.php

Page 50: Grok Drupal (7) Theming

block.tpl.php block.tpl.php

poll-vote.tpl.php poll-results--block.tpl.php

poll-bar--block.tpl.php

Page 51: Grok Drupal (7) Theming

Fields are in core It's nice tohave a home.

Page 52: Grok Drupal (7) Theming

field.tpl.php

Page 53: Grok Drupal (7) Theming

field.tpl.php

<div class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>> <?php if (!$label_hidden) : ?> <div class="field-label"<?php print $title_attributes; ?>><?php print $label ?>:&nbsp;</div> <?php endif; ?> <div class="field-items"<?php print $content_attributes; ?>> <?php foreach ($items as $delta => $item) : ?> <div class="field-item <?php print $delta % 2 ? 'odd' : 'even'; ?>"<?php print $item_attributes[$delta]; ?>><?php print render($item); ?></div> <?php endforeach; ?> </div></div>

Page 54: Grok Drupal (7) Theming

page.tpl.php

node.tpl.php

comment-wrapper.tpl.phpcomment.tpl.php

block.tpl.php

html.tpl.php

Page 55: Grok Drupal (7) Theming

page.tpl.php

node.tpl.php

comment-wrapper.tpl.phpcomment.tpl.php

block.tpl.php

html.tpl.php

region.tpl.php

region.tpl.php region.tpl.php

region.tpl.php

Page 56: Grok Drupal (7) Theming

region.tpl.php

Page 57: Grok Drupal (7) Theming

region.tpl.php

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

Page 58: Grok Drupal (7) Theming

So if all regions use the same template,how does Drupal know which region?

Page 59: Grok Drupal (7) Theming
Page 60: Grok Drupal (7) Theming

<?php print render($page['header']); ?>

<?php print render($page['content']); ?>

<?php print render($page['sidebar_first']); ?>

<?php print render($page['sidebar_second']); ?>

<?php print render($page['footer']); ?>

<?php print render($page['help']); ?>

<?php print render($page['highlight']); ?>

Page 61: Grok Drupal (7) Theming

All regions in your theme must be declared,or else you get these defaults.

Page 62: Grok Drupal (7) Theming

Where the heck are all these templates?

Page 63: Grok Drupal (7) Theming

example.com/modules

BUT DON'T EDIT THEM THERE!

Page 64: Grok Drupal (7) Theming

scaryPreprocessdoesn't have to be

Page 65: Grok Drupal (7) Theming
Page 66: Grok Drupal (7) Theming

!"!#$%&!"!#$%&

'&()*+#',-./0,&-'&()*+#',-./0,&-

!"#$%%&#'&()#*+,-.(#

!""#$%!&'()*+*,!"!-.+"!"!///-%!&'()*+*,!"!-.+"!

May I recommend....PHP for Drupal Designers,

by Emma Jane Hogbindesigntotheme.com

Page 67: Grok Drupal (7) Theming

So how to go about creating a theme?

Page 68: Grok Drupal (7) Theming

• theme .info file

• page.tpl.php

• *.tpl.php files as needed to override core

• template.php for your preprocess and postprocess

• background images

Create a theme from scratch, making everything

Page 69: Grok Drupal (7) Theming

or make a baby!

Page 70: Grok Drupal (7) Theming

Sub-themesinherit everything from parent theme,except what is overridden.

Page 71: Grok Drupal (7) Theming

base.css

Inheritance

style.css

forms.css

style.css

base.css

Page 72: Grok Drupal (7) Theming

page.tpl.php

Inheritance

node.tpl.php

block.tpl.php

node.tpl.php

page.tpl.php

Page 73: Grok Drupal (7) Theming

Many good base themes

• AdaptiveTheme

• Basic

• Blueprint

• Framework

• Fusion

• Genesis

• Mobile

• NineSixty

• Stark

• Studio

• Zen

Page 74: Grok Drupal (7) Theming

Create your theme

example.com/themes/

Page 75: Grok Drupal (7) Theming

Create your theme

example.com/themes/

example.com/sites/all/themes/yourtheme

Page 76: Grok Drupal (7) Theming

yourtheme.info

Page 77: Grok Drupal (7) Theming

yourtheme.info

name = yourthemedescription = This is where you describe your theme in words.version = 1.0

; Requirementsbase theme = ninesixtycore = 7.xengine = phptemplate

; Stylesheetsstylesheets[screen][] = styles/base.cssstylesheets[screen][] = styles/layout.cssstylesheets[screen][] = styles/colors.cssstylesheets[screen][] = styles/forms.cssstylesheets[print][] = styles/print.css

; Regionsregions[header] = Headerregions[help] = Helpregions[highlight] = Highlightregions[content] = Contentregions[page_top] = Page topregions[page_bottom] = Page bottomregions[indicators] = Indicatorsregions_hidden[] = indicators

; Scriptsscripts[] = scripts/twitter.js

Page 78: Grok Drupal (7) Theming

yourtheme.info

name = yourthemedescription = This is where you describe your theme in words.version = 1.0

; Requirementsbase theme = ninesixtycore = 7.xengine = phptemplate

; Stylesheetsstylesheets[screen][] = styles/base.cssstylesheets[screen][] = styles/layout.cssstylesheets[screen][] = styles/colors.cssstylesheets[screen][] = styles/forms.cssstylesheets[print][] = styles/print.css

; Regionsregions[header] = Headerregions[help] = Helpregions[highlight] = Highlightregions[content] = Contentregions[page_top] = Page topregions[page_bottom] = Page bottomregions[indicators] = Indicatorsregions_hidden[] = indicators

; Scriptsscripts[] = scripts/twitter.js

new!

Page 79: Grok Drupal (7) Theming

Template Suggestions

• Create a base template of that type

• Create variations on it to apply in certain circumstances

• No coding necessary

http://drupal.org/node/190815

Page 80: Grok Drupal (7) Theming

Template Suggestions

blogeventclassifiedproduct

by content type

node--blog.tpl.phpnode--event.tpl.phpnode--classified.tpl.phpnode--product.tpl.php

node.tpl.php

Page 81: Grok Drupal (7) Theming

Template Suggestions

blogeventclassifiedproduct

by content type

node--blog.tpl.phpnode--event.tpl.phpnode--classified.tpl.phpnode--product.tpl.php

node.tpl.php new!

Page 82: Grok Drupal (7) Theming

Delimiters use two: '--'Words still use one: '-'

event-meeting

event-party

node--event-meeting.tpl.php

node--event-party.tpl.php

Page 83: Grok Drupal (7) Theming

Be nice to robots!

photo: Don Soloflickr.com/photos/donsolo/3950364004/

Page 84: Grok Drupal (7) Theming

photo: Don Soloflickr.com/photos/donsolo/3950364004/

• Robot food

• An entire language to learn

• Theming just got a lot more technical

RDFa

Page 85: Grok Drupal (7) Theming

Image: Davie60rflickr.com/photos/davie60r/3274499595/

Page 86: Grok Drupal (7) Theming

Image: bbaltimoreflickr.com/photos/bbaltimore/6778028/

Robots just want to understand your site.I'm hungry!

Hmmmmm…. data…..

Hand over your RDF!

Page 87: Grok Drupal (7) Theming

It's easy!

Image: Eric__I_Eflickr.com/photos/deadling/256390679/

Dance withthem!

Page 88: Grok Drupal (7) Theming

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print $language->language; ?>" version="XHTML+RDFa 1.0" dir="<?php print $language->dir; ?>" <?php print $rdf_namespaces; ?>>

html.tpl.php

Page 89: Grok Drupal (7) Theming

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print $language->language; ?>" version="XHTML+RDFa 1.0" dir="<?php print $language->dir; ?>" <?php print $rdf_namespaces; ?>>

html.tpl.php

Page 90: Grok Drupal (7) Theming

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print $language->language; ?>" version="XHTML+RDFa 1.0" dir="<?php print $language->dir; ?>" <?php print $rdf_namespaces; ?>>

html.tpl.php

Page 91: Grok Drupal (7) Theming

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print $language->language; ?>" version="XHTML+RDFa 1.0" dir="<?php print $language->dir; ?>" <?php print $rdf_namespaces; ?>>

html.tpl.php

Page 92: Grok Drupal (7) Theming

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print $language->language; ?>" version="XHTML+RDFa 1.0" dir="<?php print $language->dir; ?>" <?php print $rdf_namespaces; ?>>

html.tpl.php

Page 93: Grok Drupal (7) Theming

Do I really need to do RDFa to use

Drupal?

No, you can just ignore it, and work on the same level as other systems.But you'll be missing

out.

Photo: FlySiflickr.com/photos/flysi/183272970/

Page 94: Grok Drupal (7) Theming

Points of Modification

• CSS

• xhtml in the template that applies

• preprocess

• module

Page 95: Grok Drupal (7) Theming

Basics to Remember

• Create your theme insites/all/themes/yourtheme

• Copy templates into your theme to make overrides

• Use template suggestions to break out distinct structures and stylings

• Use base theme to get a jump on things

• Let Drupal do what it does best

Page 96: Grok Drupal (7) Theming

Resources

• Drupal 6 » Drupal 7 theming changesdrupal.org/update/theme/6/7

• Template suggestionsdrupal.org/node/190815*

• RDFabuytaert.net/semantic-web-and-drupal-video

* Drupal 6

Page 97: Grok Drupal (7) Theming

Get Drush!

Yeah yeah yeah, I know, you don't like command line, but this will really really and for true help you save time developing so that you can spend more time designing and theming, and isn't that what you'd rather do anyway?

Video to make it easy:

http://is.gd/aZe33

Page 98: Grok Drupal (7) Theming

@lauras #d4dgrokrarepattern.com/contact

©2010 Laura Scott