Override template.php in Drupal

29
Nov
2007
Saved under:

Do you want to override template.php in Drupal, say to produce a custom administration theme? If so, boy do I have a treat for you. This technique involves using the '_phptemplate_variables()' function. Say, for example, you have created a new template page named 'page-admin.tpl.php'. You want pages who's URL ends in '/admin', '/tracker', '/node/add', '/node/edit' and any sub paths from those to use the new template page. The following code would accomplish your mission:


function _phptemplate_variables($hook, $vars = array()) {
switch ($hook) {
case 'page':
if ((arg(0) == 'admin') ||
(arg(0) == 'tracker') ||
(arg(0) == 'node' && arg(1) == 'add') ||
(arg(0) == 'node' && arg(2) == 'edit')) {
$vars['template_file'] = 'page-admin';
}
break;
}

return $vars;
}

And voila, all your admin pages will inherit their layout from page-admin.tpl.php.

If you found this useful, please leave a quick comment, thanks!

Reply

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
two times equals six
Solve this math question and enter the solution with digits. E.g. for "two plus four = ?" enter "6".

User login

Contacting Rob

Y! roberthenrylowe
AIM roberthenrylowe
ICQ 249971225
email rhlowe [at] gmail dot com

Networking Links