根据内容类型来定制drupal的页面模板

作者:网络医生 发布于:2012-3-24 23:18 Saturday 分类:Drupal

     在drupal中页面模板默认的只有page-front.tpl.php,page-node.tpl.php,page-node-1.tpl.php,page-tpl.php等

如何想根据内容类型来定义模板,即page-[content type].tpl.php,则需要自定义覆写函数。

在主题的根目录下面创建一个文件:template.php  该文件是drupal默认专门来存放主题覆写函数的。

在修改了template.php文件后必须清空缓存后才能生效。

在文件中写入以下内容:

<?php
function phptemplate_preprocess_page(&$variables)
{
     if ($node = menu_get_object())
     {
         $variables['node'] = $node;
         $suggestions = array();
         $template_filename = 'page';
         $template_filename = $template_filename .'-'. $variables['node']->type;
         $suggestions[] = $template_filename;
         $variables['template_files'] = $suggestions;
     }
}

//结尾没有 ?> 结束符,这样可以避免session出错

 

标签: drupal 主题 theme 模板

发表评论:

  • 0
  • 3
  • 2
  • 1
  • 6

Powered by emlog