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.

Chapter 3<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

The preceding example shows the full gamut of the things that you are likely see<br />

in a template file. They are as follows:<br />

• Printing a variable containing a string<br />

• Printing a translatable string using t()<br />

• Conditional if/else/endif statement<br />

• Delaying rendering on part of a render element with hide()<br />

• Printing a render element<br />

All of the PHP in a template should be limited to printing out variables. This limited<br />

amount of PHP makes it much easier for non-programmers to learn how to use<br />

template files compared to theme functions. However, for module developers, the<br />

template implementation is still very similar to the theme function implementation;<br />

the handful of differences are relatively minor.<br />

As with theme function implementations, our module would still need to invoke the<br />

theme hook using theme().<br />

$variables = array('typical' => $typical_object);<br />

$output = theme('typical_hook', $variables);<br />

[ 71 ]

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

Saved successfully!

Ooh no, something went wrong!