18.10.2016 Views

Drupal 7 Module Development

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Theming a <strong>Module</strong><br />

}<br />

// Load the account object with the node's creator and store<br />

// in a variable for themer convenience.<br />

$variables['user'] = user_load($node->uid);<br />

// Theme the username.<br />

$variables['name'] = theme('username', array(<br />

'account' => $variables['user']));<br />

Template files<br />

In order to make template files as easy to understand by non-programmers, the<br />

template should be limited to the following PHP statements:<br />

• <br />

• <br />

• <br />

• <br />

• <br />

• <br />

• <br />

• <br />

• <br />

• <br />

The print and if/elseif/else PHP snippets should be self-explanatory. However,<br />

it's important to reiterate that, in order to make <strong>Drupal</strong> multi-lingual, we should<br />

never include a bare English word in our templates; instead we should use t() in a<br />

snippet.<br />

Lastly, the show(), hide(), and render() functions are special themer-convenience<br />

functions that should only be used in template files; they should never be used in<br />

preprocess functions, theme functions or anywhere else. render() is basically the<br />

same thing as the drupal_render() function we've already learned about. The<br />

hide() function can be used on a render array's child element earlier in the template<br />

before the render array calls render(); this will prevent the child element from<br />

being included with the rest of the render array when it is rendered. For example<br />

(from Bartik's node.tpl.php):<br />

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

Saved successfully!

Ooh no, something went wrong!