Drupal 6 - как сделать вывод разных page.tpl.php а зависимости от разных адресов?

Главные вкладки

Аватар пользователя leramulina leramulina 25 декабря 2008 в 16:52

Помню, что в Drupal 5 для этого прописывала в template.php следующее:

/**
* Intercept template variables
*
* param $hook
*   The name of the theme function being executed
* param $vars
*   A sequential array of variables passed to the theme function.
*/

function _phptemplate_variables($hook, $vars = array()) {
  switch ($hook) {
    case 'page':
   
      // Add page template suggestions based on the aliased path.
      // For instance, if the current page has an alias of about/history/early,
      // we'll have templates of:
      // page-about-history-early.tpl.php
      // page-about-history.tpl.php
      // page-about.tpl.php
      // Whichever is found first is the one that will be used.
          if (module_exists('path')) {
        $alias = drupal_get_path_alias(str_replace('/edit','',$_GET['q']));
        if ($alias != $_GET['q']) {
          $suggestions = array();
          $template_filename = 'page';
          foreach (explode('/', $alias) as $path_part) {
            $template_filename = $template_filename . '-' . $path_part;
            $suggestions[] = $template_filename;
          }
        }
        $vars['template_files'] = $suggestions;
      }
      break;
         
  }
 
  return $vars;
}

А как это сделать в Drupal 6 - не знаю.

Комментарии

Аватар пользователя romass romass 25 декабря 2008 в 20:56

В друпал 6 API немного изменился. Не проверял, но должно работать

function phptemplate_preprocess_page(&$vars) {

      // Add page template suggestions based on the aliased path.
      // For instance, if the current page has an alias of about/history/early,
      // we'll have templates of:
      // page-about-history-early.tpl.php
      // page-about-history.tpl.php
      // page-about.tpl.php
      // Whichever is found first is the one that will be used.
          if (module_exists('path')) {
        $alias = drupal_get_path_alias(str_replace('/edit','',$_GET['q']));
        if ($alias != $_GET['q']) {
          $suggestions = array();
          $template_filename = 'page';
          foreach (explode('/', $alias) as $path_part) {
            $template_filename = $template_filename . '-' . $path_part;
            $suggestions[] = $template_filename;
          }
        }
        $vars['template_files'] = $suggestions;
        var_dump($suggestions);
      }

 }

Аватар пользователя ingumsky@drupal.org ingumsky@drupal.org 26 декабря 2008 в 13:19

М-м-м... А разъясните, пожалуйста, принцип. Если у меня есть несколько алиасов для одной и той же ноды, какой из них будет применяться?

PS Я точно не помню, может ли быть в Друпале более одного алиаса для ноды, так что простите, если вопрос получился глупым.

Аватар пользователя iT iT 11 января 2009 в 0:29

Добавлю, пожалуй, от себя:

По адресу /admin/build/path видим нужную ноду с внутренним адресом "node/6" и синонимом "partners" (к примеру),
нужно эту же ноду выводить по еще одному пути - "links".
Добавляем еще один синоним:

node/6 --> partners
node/6 --> links

и получаем одинаковый контент по разным адресам.

Аватар пользователя vendetta vendetta 24 февраля 2009 в 10:08

А какнить в данном ключе можно сделать, чтобы на разные словари таксономии выводились разные шаблоны страниц?