根据当前路径使用不同的drupal页面模板
在Drupal 5.0中, PHPTemplate支持在一个主题下,使用多个页面模板.根据当前的url路径(例如node/1, taxonomy/term/2, 或者user/1),PHPTemplate会按照顺序寻找相应的模板,如果找不到的话,将会采用默认的page.tpl.php模板文件。
例如,如果你访问http://www.example.com/node/1/edit,PHPtemplate将按照降序寻找下面的模板:
在Drupal 5.0中, PHPTemplate支持在一个主题下,使用多个页面模板.根据当前的url路径(例如node/1, taxonomy/term/2, 或者user/1),PHPTemplate会按照顺序寻找相应的模板,如果找不到的话,将会采用默认的page.tpl.php模板文件。
例如,如果你访问http://www.example.com/node/1/edit,PHPtemplate将按照降序寻找下面的模板:
使用drupal_add_css()函数可以将其它的样式表添加到样式表数组中去:
<?php
// Repeat this line for every CSS file added.
drupal_add_css(path_to_theme() . '/example.css', 'theme', 'all', TRUE);
// Reassemble the $styles snippet to include the new files.
$styles = drupal_get_css();
?>
PHPTemplate在page.tpl.php中提供了一个变量,如果你知道怎么使用的话,它将非常强大.
Drupal 5 ($layout)
$layout包含一个字符串,用来告诉你页面的布局:
如果用的是左栏的话,则为left
如果用的是右栏的话,则为right
如果左右栏都用的话,则为both
默认模板
下面是Drupal 5的bluemarine主题的page.tpl.php模板,让你对页面模板文件有个实际的认识。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="<?php print $language ?>" xml:lang="<?php print $language ?>">
这个模板文件定义了页面的骨架.
可用变量(按字母顺序)
$base_path
返回Drupal安装的URL基路径.最初,这将默认为/。
$breadcrumb
在页面顶部用于展示面包屑的breadcrumb。
你可以在drupal主题的node.tpl.php模板文件中使用下面的条件语句,来为摘要创建一个独特的外观:
<?php
if ($teaser) {
//if node is being displayed as a teaser
//Anything here will show up when the teaser of the post is viewed in your taxonomies or front page
} else {
//all other cases
//Anything here will show up when viewing your post at any other time, e.g. previews
?>
<?php
if (arg(0) == 'node' && is_numeric(arg(1))) {
$url_alias = drupal_get_path_alias('node/'.arg(1));
} elseif (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) {
$url_alias = drupal_get_path_alias('taxonomy/term/'.arg(2));
}
我看到很多人发帖询问如何为OG首页定制主题.我自己也想对drupal4.7版本的旧式OG首页进行升级,但是我还不能找到一种像样的方式。文档中(至少我看到的是)看起来仅仅告诉我们如何为实际的group(组)节点类型定制主题(例如node-og.tpl.php),或者在默认的og_ghp_ron主题加点过滤器。这些都不是本文要讨论的。(译者注,这里所讲的首页,是小组的首页,而不是站点的首页,一个站点可以有n多个小组,每个小组有一个自己的首页面)。