Introducing Themable Functions

The HTML output that is generated by Drupal has been carefully crafted to be accessible, lightweight, and easily styled with CSS. Despite this, you may find yourself wanting to change the HTML output in some way. Drupal takes great care to make this possible without forcing you to change the source code of the core files and modules. Instead, all HTML that is output comes from themable functions that can be overwritten from within individual themes. The role of the theme is to provide alternate versions of themable functions for the cases where different output is desired.

Keeping these changes at the theme level, rather than needing to hack core files and modules, is a great advantage when it comes to upgrading Drupal to a new version, as it saves you from hunting down all the changes in the old version and reimplementing them in the new version. It is also necessary if you intend to host multiple sites from one codebase, a topic covered in Chapter 6.

You can identify themable functions in the core includes and modules by their name, which starts with theme_. This naming convention allows Drupal to identify the function's role and purpose, and also to override it by redirecting calls to an overriding function if one is available in the theme.

Table 5-2 lists some themable functions and what they do. It is far from complete but it will give you an idea of how themable functions are used in Drupal. Notice that all of the functions listed start with theme .

Table 5-2. Some Themable Functions

Function

Location

Purpose

theme block

includes/theme.inc

Handles blocks

theme box

includes/theme.inc

Builds a container

theme breadcrumb

includes/theme.inc

Generates a breadcrumb trail

theme comment

modules/comment.module

Handles comments

theme form element

includes/theme.inc

Styles elements that are typically found in forms, such as text boxes and input tags

theme links

includes/theme.inc

Takes a list of links such as primary and secondary links and styles them

theme book navigation

modules/book.module

Is responsible for the previous, up, and next links in book hierarchies

theme page

includes/theme.inc

Generates Drupal pages

theme node

includes/theme.inc

Handles nodes

theme profile listing

modules/profile.module

Takes one user and displays her profile fields (for use in lists of users)

theme submenu

includes/theme.inc

Generates a submenu

theme user profile

modules/user.module

Generates the listing of a user's account information; the one seen by visiting user/1, for example

theme xml icon

includes/theme.inc

Generates an XML icon

Some of the themable functions listed in Table 5-2 are used often, as I'll explain next.

Some of the themable functions listed in Table 5-2 are used often, as I'll explain next.

0 0

Post a comment