18.10.2016 Views

Drupal 7 Module Development

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

A module's hook_theme implementation just needs to return an array of theme<br />

hooks it is creating. For example:<br />

/**<br />

* Implements hook_theme().<br />

*/<br />

function retro_theme() {<br />

return array(<br />

// The array key is the name of the theme hook.<br />

'wonder' => array(<br />

// Use a template and give the template's name.<br />

'template' => 'wonder',<br />

}<br />

// Specify the default variable names and their values.<br />

'variables' => array(<br />

'twin' => 'zen',<br />

'with_monkey' => FALSE,<br />

'activations' => array(),<br />

),<br />

// Add a partial pattern to help hook theme suggestion<br />

// matches.<br />

'pattern' => 'wonder__',<br />

),<br />

'austinite' => array(<br />

// Specify the name of the render element.<br />

'render element' => 'my_element',<br />

// We don't use this theme function often, so let's put<br />

// it in a separate file that is lazy loaded, if needed.<br />

'file' => 'retro.texas.inc',<br />

),<br />

);<br />

Chapter 3<br />

Let's examine this data. By default a theme hook will be assumed to be implemented<br />

as a theme function named theme_hook_name(). We can override the hook name<br />

using a function key/value inside our austinite array, but please don't confuse<br />

our poor themers; leave the default function name alone. If a theme hook instead<br />

wants to use template implementation, it needs to specify the name of the template<br />

file (without the .tpl.php extension) in the template key/value. Our wonder theme<br />

hook will use a wonder.tpl.php template.<br />

[ 87 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!