直接就在garland目录下面修改了.拷贝themes/garland下面的page.tpl.php,并将复制品重命名为page-front.tpl.php,现在后者就负责首页的外观了,但是现在我们还没有在里面做任何修改。打开page-front.tpl.php,
garland的页面模板虽然丑陋,但是却相当经典。以前我做页面模板时,就是仿照这个,通常header部分都是直接拷贝这里的。
<?php
// $Id: page.tpl.php,v 1.18 2008/01/24
?><!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" xml:lang="<?php print $language->language ?>" lang="<?php print $language->language ?>" dir="<?php print $language->dir ?>">
<head>
<title><?php print $head_title ?></title>
<?php print $head ?>
<?php print $styles ?>
<?php print $scripts ?>
<!--[if lt IE 7]>
<?php print phptemplate_get_ie_styles(); ?>
<![endif]-->
</head>
注意这里面的php语句,$head_title,$head,$styles,$scripts,这些都是页面模板中的变量,还有$language,它现在成了一个对象变量了。具体的含义,可参看本站的译文还有官方的手册。
紧接着的代码,是网页最上面的一些logo,口号什么的,
<div id="header-region" class="clear-block"><?php print $header; ?></div>
<div id="wrapper">
<div id="container" class="clear-block">
<div id="header">
<div id="logo-floater">
<?php
// Prepare header
$site_fields = array();
if ($site_name) {
$site_fields[] = check_plain($site_name);
}
if ($site_slogan) {
$site_fields[] = check_plain($site_slogan);
}
$site_title = implode(' ', $site_fields);
if ($site_fields) {
$site_fields[0] = '<span>'. $site_fields[0] .'</span>';
}
$site_html = implode(' ', $site_fields);
if ($logo || $site_title) {
print '<h1><a href="'. check_url($front_page) .'" title="'. $site_title .'">';
if ($logo) {
print '<img src="'. check_url($logo) .'" alt="'. $site_title .'" id="logo" />';
}
print $site_html .'</a></h1>';
}
?>
</div>
这些我们也不用管。
下面的这段是一级链接,和二级链接的输出。
<?php if (isset($primary_links)) : ?>
<?php print theme('links', $primary_links, array('class' => 'links primary-links')) ?>
<?php endif; ?>
<?php if (isset($secondary_links)) : ?>
<?php print theme('links', $secondary_links, array('class' => 'links secondary-links')) ?>
<?php endif; ?>
</div> <!-- /header -->
再下面是左栏区域:
<?php if ($left): ?>
<div id="sidebar-left" class="sidebar">
<?php if ($search_box): ?><div class="block block-theme"><?php print $search_box ?></div><?php endif; ?>
<?php print $left ?>
</div>
<?php endif; ?>
如果左栏区域中没有区块的话,这里的html片段就不用输出了。
我们所关心的到了:
<div id="center"><div id="squeeze"><div class="right-corner"><div class="left-corner">
<?php print $breadcrumb; ?>
<?php if ($mission): print '<div id="mission">'. $mission .'</div>'; endif; ?>
<?php if ($tabs): print '<div id="tabs-wrapper" class="clear-block">'; endif; ?>
<?php if ($title): print '<h2'. ($tabs ? ' class="with-tabs"' : '') .'>'. $title .'</h2>'; endif; ?>
<?php if ($tabs): print '<ul class="tabs primary">'. $tabs .'</ul></div>'; endif; ?>
<?php if ($tabs2): print '<ul class="tabs secondary">'. $tabs2 .'</ul>'; endif; ?>
<?php if ($show_messages && $messages): print $messages; endif; ?>
<?php print $help; ?>
<div class="clear-block">
<?php print $content ?>
</div>
<?php print $feed_icons ?>
<div id="footer"><?php print $footer_message . $footer ?></div>
</div></div></div></div> <!-- /.left-corner, /.right-corner, /#squeeze, /#center -->
这里面放的主内容,包括节点的标题,各种字段,属性。即便是在别的主题中,通常我也是直接拷贝这一整段代码,通常需要略作修改,比如这里,我们需要把标题删去,也就是删除以下内容:
<?php if ($title): print '<h2'. ($tabs ? ' class="with-tabs"' : '') .'>'. $title .'</h2>'; endif; ?>
这样“drupal国内新闻”这一标题就不出现在顶部了,当然现在啥也没有了。
如何去掉“Mon, 10/20/2008 - 16:59 — admin”这样的信息呢?有不少初学者都这样问。是不是删除以下内容:
<?php if ($show_messages && $messages): print $messages; endif; ?>
就可以了。
我试了一下,不行,看来文章的作者,及发布日期不在这里控制。你可以逐个的删除这里面的变量,来观察页面内容的变化。
其中<?php print $content ?>的$content变量,是由节点模板控制的,也就是node.tpl.php,这个是最一般的节点模板,有时候我们需要更具体的节点模板,这个将在接下来的文章中讲到。
再下面是右栏:
<?php if ($right): ?>
<div id="sidebar-right" class="sidebar">
<?php if (!$left && $search_box): ?><div class="block block-theme"><?php print $search_box ?></div><?php endif; ?>
<?php print $right ?>
</div>
<?php endif; ?>
</div> <!-- /container -->
</div>
<!-- /layout -->
这个和左栏一样,不过就是放在了右边罢了,左右是对成的。
最后面的这个变量一定要注意,
<?php print $closure ?>
</body>
</html>
$closure是干什么的,我们先别管,忘了这个变量,会犯莫名其妙的错误的,有一次,我同事制作drupal主题,出现了错误,怎么都找不到,搞了半天,我让他从头开始,一个一个对照,看到底哪里少东西了,最后发现,忘记了这个变量<?php print $closure ?>。当你制作drupal主题的时候,出了问题,也应该看看是不是缺了这个变量。这个是经验之谈。
相关链接: Think in Drupal