Вы здесь

template.php

Если вы хотите переопределить функции, которые не входят в основной список (block, box, comment, node и page), то вам нужно заявить об этом PHPTemplate. Чтобы сделать это, создайте в папке темы файл template.php. Этот файл должен начинаться с открывающего тега PHP, — <?php — а закрывающий тег — ?> — использовать не следует.

В качестве примера, будет использована функция theme_item_list() (список всех функций тем можно найти на сайте api.drupal.org. Функция выглядит следующим образом:

<?php
 
function theme_item_list($items = array(), $title = NULL) {
 
$output = '<div class="item-list">';
  if (isset(
$title)) {
   
$output .= '<h3>'. $title .'</h3>';
  }
?>

Теперь, давайте сделаем ответвление (в котором переопределим функцию).

<?php
/**
* Catch the theme_item_list function, and redirect through the template api
*/
function phptemplate_item_list($items = array(), $title = NULL) {
 
// Pass to phptemplate, including translating the parameters to an associative array.
  // The element names are the names that the variables
  // will be assigned within your template.
 
return _phptemplate_callback('item_list', array('items' => $items, 'title' => $title));
}
?>

Мы переписали слово theme в названии функции на слово phptemplate и использовали вызов _phptemplate_callback(), чтобы обработать параметры через PHPTemplate. Теперь нам нужно создать в папке темы файл item_list.tpl.php, который будет использоваться для оформления списков пунктов. Начнём с копирования исходного кода функции theme_item_list(). Отметьте: не обёртывайте этот код в функцию.

<?php
  $output
= '<div class="item-list">';
  if (isset(
$title)) {
   
$output .= '<h3>'. $title .'</h3>';
  }
?>

Пример template.php

<?php
// $Id: template.php,v 1.4.2.1 2007/04/18 03:38:59 drumm Exp $

/**
* Sets the body-tag class attribute.
*
* Adds 'sidebar-left', 'sidebar-right' or 'sidebars' classes as needed.
*/
function phptemplate_body_class($sidebar_left, $sidebar_right) {
  if ($sidebar_left != '' && $sidebar_right != '') {
    $class = 'sidebars';
  }
  else {
    if ($sidebar_left != '') {
      $class = 'sidebar-left';
    }
    if ($sidebar_right != '') {
      $class = 'sidebar-right';
    }
  }

  if (isset($class)) {
    print ' class="'. $class .'"';
  }
}

/**
* Return a themed breadcrumb trail.
*
* @param $breadcrumb
*   An array containing the breadcrumb links.
* @return a string containing the breadcrumb output.
*/
function phptemplate_breadcrumb($breadcrumb) {
  if (!empty($breadcrumb)) {
    return '<div class="breadcrumb">'. implode(' › ', $breadcrumb) .'</div>';
  }
}

/**
* Allow themable wrapping of all comments.
*/
function phptemplate_comment_wrapper($content, $type = null) {
  static $node_type;
  if (isset($type)) $node_type = $type;

  if (!$content || $node_type == 'forum') {
    return '<div id="comments">'. $content . '</div>';
  }
  else {
    return '<div id="comments"><h2 class="comments">'. t('Comments') .'</h2>'. $content .'</div>';
  }
}

/**
* Override or insert PHPTemplate variables into the templates.
*/
function _phptemplate_variables($hook, $vars) {
  if ($hook == 'page') {

    if ($secondary = menu_secondary_local_tasks()) {
      $output = '<span class="clear"></span>';
      $output .= "<ul class="tabs secondary">\n". $secondary ."</ul>\n";
      $vars['tabs2'] = $output;
    }

    // Hook into color.module
    if (module_exists('color')) {
      _color_page_alter($vars);
    }
    return $vars;
  }
  return array();
}

/**
* Returns the rendered local tasks. The default implementation renders
* them as tabs.
*
* @ingroup themeable
*/
function phptemplate_menu_local_tasks() {
  $output = '';

  if ($primary = menu_primary_local_tasks()) {
    $output .= "<ul class="tabs primary">\n". $primary ."</ul>\n";
  }

  return $output;
}

Комментарии

Изображение пользователя Санхип

// $Id: template.php,v 1.4.2.1 2007/04/18 03:38:59 drumm Exp $

что означает эта строчка?
может кто-нибудь разложить на составляющие и объяснить каждое значение?

меня интересует конкретный вопрос - это задается системой или программистом, который данный файл создает/изменяет?

Изображение пользователя Анонимно

http://setegnom.com/node/101 - стандарты кодирования. Я так понял что эта строчка используется системой CVS и в исходный //$Id включает полезную информацию указанную выше