Top Banner
Drupal Theming December 5th 2012 NWDUG
21

Drupal theming

Jan 28, 2015

Download

Technology

Philip Norton

A presentation given at the December meetup of the North West Drupal User Group (NWDUG) by Phil Norton and Mike Bell.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Drupal theming

Drupal Theming

December 5th 2012 NWDUG

Page 2: Drupal theming

Drupal Themes

Some standard ones:- Garland/Bartik - Drupal Core- Zen- Omega- Boilerplate

Drupal themes, ordered by popularity:http://bit.ly/XqhSop

Page 3: Drupal theming

Anatomy Of A Drupal Theme

Page 4: Drupal theming

<theme name>.info

Required.

Also used for theme specific settings.

name = 'My amazing theme'description = 'My amazing theme wot is amazing'core = '7.x'engine = 'phptemplate'screenshot = 'screenshot.png'

Page 5: Drupal theming

<theme name>.info

Add stylesheets:

stylesheets[all][] = style.css

Add JavaScript:

scripts[] = myscript.js

Control items on theme config page:

features[] = logo

Page 6: Drupal theming

Sub themes

Don't hack other themes; create a sub theme.

base theme = garland

Page 7: Drupal theming

Templates

node.tpl.phppage.tpl.phphtml.tpl.phpblock.tpl.phpregion.tpl.phpcomment.tpl.php***.tpl.php - defined by a module (eg, Views)

Page 8: Drupal theming

Overriding Templates

Don't hack core templates!

To make a custom node template for a content type.

- Copy node.tpl.php from /modules/node into your template directory.

- Rename to node--<type>.tpl.php

Page 9: Drupal theming

Overriding Templates

Templates can usually be overridden hierarchically

page.tpl.phppage--node.tpl.phppage--node--2226.tpl.php

block.tpl.phpblock--region.tpl.phpblock--module-name.tpl.phpblock--module-name-delta.tpl.php

Page 10: Drupal theming

template.php

Theme specific overrides.

Either by theme name or rendering engine.

For just this theme:mytheme_breadcrumb($variables)

For this theme an all sub themes:phptemplate_breadcrumb($variables)

Page 11: Drupal theming

Preprocess Hooks

Alter elements before they are sent to a theme function or template.

hook_preprocess_html(&$variables)

hook_preprocess_page(&$variables)

hook_preprocess_node(&$variables)

Page 12: Drupal theming

Themeing from a Module

hook_theme();

Be nice to your themers!

function hook_theme($existing, $type, $theme, $path) { return array( 'system_date_time_settings' => array( 'render element' => 'form', 'file' => 'system.admin.inc', ), );}

Page 13: Drupal theming

Regions

Where blocks go.

In your info file:

regions[header] = 'Header'

In your page.tpl.php template:

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

Page 14: Drupal theming

render()

Renders content.

print render($content);

Used with hide() and show().

hide($content['comments']);print render($content);

Page 15: Drupal theming

Theme All The Things!

It is theoretically possible to alter every theme element in Drupal*

Page 16: Drupal theming

* It's probably not a good idea though

Page 17: Drupal theming

Tips

Create a subdirectory of templates in your theme.

If you get stuck turn on the Stark theme to see the raw HTML being generated.

Think before including JavaScript libraries as Drupal has a bunch.

Page 18: Drupal theming

Tips

When planning a site think about where you content will go and what blocks go in what region.

Use $var['theme_hook_suggestions'] in you preprocess hooks to see what templates are available.

Use devel themer module to see more information about what is theming an element.

Page 19: Drupal theming

Resources

Drupal.org .info files:http://drupal.org/node/171205

Drupal themes, ordered by popularity:http://bit.ly/XqhSop

Questions?

Page 20: Drupal theming

Philip Norton && Mike BellBloghttp:///www.norton42.org.uk/http://www.digital006.com

Twitter@philipnorton42@mikebell_

#! codehttp://www.hashbangcode.com/

Page 21: Drupal theming

Before we forget

What subject next?

Next meetup date is 2nd Jan - Postpone to week after- Postpone to month after