Grok Drupal (7) Theming--Notes
Even though I have been theming for a while, I thought I would check out my Google Summer of Code mentor Laura Scott's presentation on Groking Drupal (7) Theming.
It is a great introduction that really helps form a mental model for how the theming layer works. It would be great for some of the other researchers here at DERI who haven't yet grappled with the theme layer... really a must watch for anyone who is creating modules with HTML output who hasn't yet figured out the theme layer.
A Drupal theme has CSS files, image files, the template files, JavaScript, and an info file. There are also new preprocess and process files.
The heart is the template files, and the templates are what confuse most people. Here is the structure.
html.tpl.php
- DOCTYPE
- head
- CSS and header JS
- body container (which contains output of page.tpl.php)
page.tpl.php
- logo
- main title
- regions
- footer
- and the output of other templates
node.tpl.php
- node title
- node author
- post date
- node content
- node taxonomy terms
- node links
- and now contains and governs the comments as output by comment-wrapper.tpl.php
comment-wrapper.tpl.php
- comment area title
- and the output of comment.tpl.php
comment.tpl.php
- comment title
- comment author
- comment content
- comment links
region.tpl.php
- contains output of block.tpl.php
block.tpl.php
- block title
- block content
[13:00] Every module's output also has a template file (in theory). There are 42 .tpl.php files defined by modules in core. You can override these by moving them to your theme folder. DON'T CHANGE THE ORIGINAL FILE, but instead override it.
The classes in the template files add contextual information. For instance, the classes in the block will list the module that is outputting the block and the block number.
UPDATE: I just had a question from a colleague who was having a problem precisely because he wasn't using the theme layer to make his module's output themable... here is the page for figuring out how to use the theme layer in your module http://drupal.org/node/165706.
[24:00] Laura used poll as an example of a module with tpl.php files. It is a good example to use if you want to see how to register template files conditionally, for instance, in a block. Look at poll_theme() and then search for function template_preprocess_poll_results() to see how it is applied conditionally.
Preprocess is for defining new variables. You can do things like re-rendering the taxonomy array to be broken out by vocabulary.
[40:00] New in the .info file, you can declare regions as hidden so you can place blocks there, but it doesn't show up to the site administrator for them to place blocks.
[43:00] Template suggestions can be used to override a tpl.php file in a particular circumstance, such as the display of a page of a certain content type. More info at http://drupal.org/node/190895
[46:00] Nice shout out about RDFa... and a shout out to me too! for the video in the keynote.