Converting 4.6.x themes to 4.7.x

Last modified: October 1, 2006 - 01:17

Table row coloring

The class names for alternating table rows have been changed from light and dark to odd and even.

$site removed from page.tpl.php

Any uses of the variable $site should be replaced with $site_name.

$seqid is now $id

If you were using the $seqid counter, please change all occurences to simply $id. As $id is not used by any core modules (and should not be used) this is not likely to cause any problems.

New theme_username()

You can now change the appearance of your user's names by implementing this function. Used to be format_name().

theme_node: $main => $teaser

In the theme_node() function, $main has been renamed to $teaser for consistency. This possibly affects the template engine (phptemplate_node()) as well as the template file: node.tpl.php.

Regions

Drupal theme authors can now define and implement any number of 'regions' for content to be rendered into. This regioning system replaces the previous 'left' and 'right' sidebar regions and should enable much more flexible layout and design, and requires changes to every theme and theme engine.

At a minimum, all plain PHP themes must now include a mytheme_regions() function in their .theme file, defining the available regions. If left and right sidebars were already available and no new regions were introduced, a plain PHP theme could be upgraded simply by adding the following function:

<?php
function mytheme_regions() {
  return array(
      
'left' => t('left sidebar'),
      
'right' => t('right sidebar')
  );
}
?>

Want to do more? Look to the regioning information in the plain PHP theme author's guide.

To upgrade PHPTemplate-based themes, the minimum change needed is to add a "header" region to the page.tpl.php file (a region below the top of page banner). In bluemarine, the added region looked like this:

  <tr>
    <td colspan="2"><div><?php print $header ?></div></td>
  </tr>

See the page on regioning in PHPTemplate themes for tips on how to introduce your own custom regions.

Like plain PHP themes, template engines besides the core PHPTemplate one can be minimally upgraded simply by adding a mythemeengine_regions() function defining the already-available left and right regions. But full support for regioning will require more extensive changes. The phptemplate.engine section of the recently-applied regioning patch should be a partial guide for what's needed.

theme_comment_thread_min() and theme_comment_thread max() renamed

theme_comment_thread_max() has been renamed to theme_comment_thread_expanded(). theme_comment_thread_min() has been renamed to theme_comment_thread_collapsed().

Forum icons now controlled by the theme

_forum_icon() has been replaced by theme_forum_icon(). Themes can now override the display of forum icons which appear next to a topic.

Drupal.css changes

Changes since 4.6 can be viewed from the CVS log

We no longer use the <base> element

In versions of Drupal prior to 4.7, we used the HTML BASE tag to indicate the base to which all relative links should be appended to. In Drupal 4.7, however, the BASE tag has been removed entirely. All Drupal functions that specifically return URLs (such as l() or url() or the various theme_add_style() features) have been updated to now return the base_path() prepended to any URLs. If, however, you are manually creating your own URLs and not using one of Drupal's internal functions, you'll need to do something like:

BEFORE:
print '<link rel="stylesheet" type="text/css" href="themes/chameleon/common.css" />";

AFTER (generic approach):
print '<link rel="stylesheet" type="text/css" href='. base_path() .'"themes/chameleon/common.css" />";

AFTER (strongest specific approach, using Drupal functions):

// this would only apply to styles, naturally
print theme('stylesheet_import', base_path() . path_to_theme() ."/common.css");

theme_onload_attribute has been removed; use JS addLoadEvent() instead

This is covered in more detail in the modules upgrade section.

Javascript and 4.7

merlinofchaos - December 16, 2005 - 22:40

If using onload in the body tag in your 4.6 theme, 4.7 will choke on it. Instead use this code in your .js file

if (isJsEnabled()) {
  addLoadEvent(func);
}

-- Merlin

[Point the finger: Assign Blame!]
[Read my writing: ehalseymiles.com]

No more relative paths

drewish - January 30, 2006 - 03:51

Per #13148, themes can no longer rely on having a <base> element in <head>. As such, all paths can no longer be relative, they'll need to be prefixed with the global variable $base_url.

not quite

moshe weitzman - February 22, 2006 - 07:22

root relative links are fine. use the phptemplate variable $directory to point to your theme dir for images and such.

Not quite

Taran - May 6, 2006 - 23:17

the theme may not be phptemplate based.

KnowProSE.com
OpenDepth.com

Some CSS changes

markus_petrux - January 30, 2006 - 21:35

I do not exactly recall which patch(es), but at least, div.menu has been replaced with ul.menu. Theme and module authors may need to review the way they generate unordered lists.

It may worth to mention that class="active" is now automatically added by l().

The search box has changed.

mjolley@buy-hot.com - May 18, 2006 - 05:31

I'm using box_grey and noticed that the search button string is missing. It seems that $search_button_text no longer exists and that

<input class="form-text" type="text" size="15" value="" name="edit[keys]" /><input class="form-submit" type="submit" value="<?php print $search_button_text ?>" />

Has been replaced in blumarine and pushbutton by

<?php
print $search_box
?>

 
 

Drupal is a registered trademark of Dries Buytaert.