深度阅读

"根据内容类型定制drupal模板"

作者
作者
2023年08月22日
更新时间
5.58 分钟
阅读时间
0
阅读量

找到theme所在的目录中的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;
}
}
?>
代码添加完毕之后,只需为不同的node type建议不同的layout文件到theme目录即可了,如:
forum -> page-forum.tpl.php
blog -> page-blog.tpl.php
book -> page-book.tpl.php

博客作者

热爱技术,乐于分享,持续学习。专注于Web开发、系统架构设计和人工智能领域。