Drupal theming

Uploaded on

A presentation given at the December meetup of the North West Drupal User Group (NWDUG) by Phil Norton and Mike Bell.

A presentation given at the December meetup of the North West Drupal User Group (NWDUG) by Phil Norton and Mike Bell.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
  • @mallton I do more or less the same thing for many of my projects, but I am usually converting HTML templates into Drupal themes so that makes sense.

    Using sub themes is a good way of creating a theme and being able to update the parent theme. I don't think there is a good case for doing this with simple themes like Basic that don't contain much code.
    Are you sure you want to
    Your message goes here
  • Nice overview! My personal favorite base theme is Basic, but I know everyone has their preferences.

    For each new site and custom theme, I completely change a new copy of Basic - I edit basic.info, theme-settings.php and template.php accordingly (changing 'basic' to the new theme name). While I certainly wouldn't recommend that for casual Drupal users, is there a good case reason why I shouldn't do that for my clients?
    Are you sure you want to
    Your message goes here
No Downloads


Total Views
On Slideshare
From Embeds
Number of Embeds



Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

    No notes for slide


  • 1. Drupal Theming December 5th 2012 NWDUG
  • 2. Drupal ThemesSome standard ones:- Garland/Bartik - Drupal Core- Zen- Omega- BoilerplateDrupal themes, ordered by popularity:http://bit.ly/XqhSop
  • 3. Anatomy Of A Drupal Theme
  • 4. <theme name>.infoRequired.Also used for theme specific settings.name = My amazing themedescription = My amazing theme wot is amazingcore = 7.xengine = phptemplatescreenshot = screenshot.png
  • 5. <theme name>.infoAdd stylesheets:stylesheets[all][] = style.cssAdd JavaScript:scripts[] = myscript.jsControl items on theme config page:features[] = logo
  • 6. Sub themesDont hack other themes; create a sub theme.base theme = garland
  • 7. Templatesnode.tpl.phppage.tpl.phphtml.tpl.phpblock.tpl.phpregion.tpl.phpcomment.tpl.php***.tpl.php - defined by a module (eg, Views)
  • 8. Overriding TemplatesDont hack core templates!To make a custom node template for a contenttype.- Copy node.tpl.php from /modules/node into your templatedirectory.- Rename to node--<type>.tpl.php
  • 9. Overriding TemplatesTemplates can usually be overriddenhierarchicallypage.tpl.phppage--node.tpl.phppage--node--2226.tpl.phpblock.tpl.phpblock--region.tpl.phpblock--module-name.tpl.phpblock--module-name-delta.tpl.php
  • 10. template.phpTheme 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)
  • 11. Preprocess HooksAlter elements before they are sent to a themefunction or template.hook_preprocess_html(&$variables)hook_preprocess_page(&$variables)hook_preprocess_node(&$variables)
  • 12. Themeing from a Modulehook_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, ), );}
  • 13. RegionsWhere blocks go.In your info file:regions[header] = HeaderIn your page.tpl.php template:<?php print render($page[header_nav]); ?>
  • 14. render()Renders content.print render($content);Used with hide() and show().hide($content[comments]);print render($content);
  • 15. Theme All The Things!It is theoretically possible to alter every themeelement in Drupal*
  • 16. * Its probably not a good idea though
  • 17. TipsCreate a subdirectory of templates in yourtheme.If you get stuck turn on the Stark theme to seethe raw HTML being generated.Think before including JavaScript libraries asDrupal has a bunch.
  • 18. TipsWhen planning a site think about where youcontent will go and what blocks go in whatregion.Use $var[theme_hook_suggestions] in youpreprocess hooks to see what templates areavailable.Use devel themer module to see moreinformation about what is theming an element.
  • 19. ResourcesDrupal.org .info files:http://drupal.org/node/171205Drupal themes, ordered by popularity:http://bit.ly/XqhSop Questions?
  • 20. Philip Norton && Mike BellBloghttp:///www.norton42.org.uk/http://www.digital006.comTwitter@philipnorton42@mikebell_#! codehttp://www.hashbangcode.com/
  • 21. Before we forgetWhat subject next?Next meetup date is 2nd Jan- Postpone to week after- Postpone to month after