主题化-B-使用tpl模板定制XHTML(page.tpl.php)(视频)
本节开始学习使用Drupal的模板来定制XHTML输出,大部分情况下使用模板文件即可满足我们的需求。
相关链接:
Drupal主题模板简图

本例区域示意图

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" xml:lang="
<?php print $language->language ?>" lang="
<?php print $language->language ?>" dir="
<?php print $language->dir ?>">
<head>
<?php print $head; ?>
<title>
<?php print $head_title; ?></title>
<?php print $styles; ?>
<?php print $scripts; ?>
<script type="text/javascript">
<?php /* Needed to avoid Flash of Unstyled Content in IE */ ?> </script>
</head>
<body class="root
<?php print $body_classes; ?> no-scroller node-
<?php print $node->nid;; ?>">
<div id="wrap">
<div id="header">
<div id="logo-title">
<?php if (!empty($logo)): ?>
<a href="
<?php print $front_page; ?>" title="
<?php print t
('Home'); ?>" rel="home" id="logo">
<img src="
<?php print $logo; ?>" alt="
<?php print t
('Home'); ?>" />
</a>
<?php endif; ?>
<?php if (!empty($site_name)): ?>
<h2 id="site-name">
<a href="
<?php print $front_page ?>" title="
<?php print t
('Home'); ?>" rel="home"><span>
<?php print $site_name; ?></span></a>
</h2>
<?php endif; ?>
</div> <!-- /logo-title -->
<?php if (!empty($search_box)): ?>
<div id="search-box">
<?php print $search_box; ?></div>
<?php endif; ?>
<?php if (!empty($header)): ?>
<div id="header-region">
<?php print $header; ?>
</div>
<?php endif; ?>
<?php if (!empty($breadcrumb)): ?><div id="breadcrumb">
<?php print $breadcrumb; ?></div>
<?php endif; ?>
</div> <!-- /header -->
<div id="sidebar">
<div id="navigation" class="menu
<?php if (!empty($primary_links)) { print "withprimary"; } if (!empty($secondary_links)) { print " withsecondary"; } ?> ">
<?php if (!empty($primary_links)): ?>
<div id="primary" class="clear-block">
<?php print theme
('links', $primary_links, array('class' => 'primary-links')); ?>
</div>
<?php endif; ?>
<?php if (!empty($secondary_links)): ?>
<div id="secondary" class="clear-block">
<?php print theme
('links', $secondary_links, array('class' => 'links secondary-links')); ?>
</div>
<?php endif; ?>
</div> <!-- /navigation -->
<?php print $sidebar; ?>
</div> <!-- /sidebar -->
<div id="contentBox">
<?php if (!empty($title)): ?>
<h1 class="title" id="page-title">
<?php print $title; ?></h1>
<?php endif; ?>
<div id="contentInner">
<?php if (!empty($mission)): ?>
<div id="mission">
<?php print $mission; ?></div>
<?php endif; ?>
<div id="content">
<?php if (!empty($tabs)): ?>
<div class="tabs">
<?php print $tabs; ?></div>
<?php endif; ?>
<?php if (!empty($messages)): print $messages; endif; ?>
<?php if (!empty($help)): print $help; endif; ?>
<div id="content-content" class="clear-block">
<?php print $content; ?>
</div> <!-- /content-content -->
<?php print $feed_icons; ?>
</div> <!-- /content -->
</div>
</div> <!-- /contentInner /contentBox -->
</div>
<div id="footer">
<?php print $footer_message; ?>
<?php if (!empty($footer)): print $footer; endif; ?>
</div> <!-- /footer -->
<?php print $closure; ?>
</body>
</html>
page-album.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" xml:lang="
<?php print $language->language ?>" lang="
<?php print $language->language ?>" dir="
<?php print $language->dir ?>">
<head>
<?php print $head; ?>
<title>
<?php print $head_title; ?></title>
<?php print $styles; ?>
<?php print $scripts; ?>
<script type="text/javascript">
<?php /* Needed to avoid Flash of Unstyled Content in IE */ ?> </script>
</head>
<body class="root
<?php print $body_classes; ?> scroller">
<div id="wrap">
<div id="header">
<div id="logo-title">
<?php if (!empty($logo)): ?>
<a href="
<?php print $front_page; ?>" title="
<?php print t
('Home'); ?>" rel="home" id="logo">
<img src="
<?php print $logo; ?>" alt="
<?php print t
('Home'); ?>" />
</a>
<?php endif; ?>
<?php if (!empty($site_name)): ?>
<h2 id="site-name">
<?php print $node->type; ?>
<a href="
<?php print $front_page ?>" title="
<?php print t
('Home'); ?>" rel="home"><span>
<?php print $site_name; ?></span></a>
</h2>
<?php endif; ?>
</div> <!-- /logo-title -->
<?php if (!empty($search_box)): ?>
<div id="search-box">
<?php print $search_box; ?></div>
<?php endif; ?>
<?php if (!empty($header)): ?>
<div id="header-region">
<?php print $header; ?>
</div>
<?php endif; ?>
<?php if (!empty($breadcrumb)): ?><div id="breadcrumb">
<?php print $breadcrumb; ?></div>
<?php endif; ?>
</div> <!-- /header -->
<div id="sidebar">
<div id="navigation" class="menu
<?php if (!empty($primary_links)) { print "withprimary"; } if (!empty($secondary_links)) { print " withsecondary"; } ?> ">
<?php if (!empty($primary_links)): ?>
<div id="primary" class="clear-block">
<?php print theme
('links', $primary_links, array('class' => 'primary-links')); ?>
</div>
<?php endif; ?>
<?php if (!empty($secondary_links)): ?>
<div id="secondary" class="clear-block">
<?php print theme
('links', $secondary_links, array('class' => 'links secondary-links')); ?>
</div>
<?php endif; ?>
</div> <!-- /navigation -->
<?php print $sidebar; ?>
</div> <!-- /sidebar -->
<div id="contentBox">
<?php if (!empty($title)): ?>
<h1 class="title" id="page-title">
<?php print $title; ?></h1>
<?php endif; ?>
<div id="contentInner">
<?php if (!empty($mission)): ?>
<div id="mission">
<?php print $mission; ?></div>
<?php endif; ?>
<div id="content">
<?php if (!empty($tabs)): ?>
<div class="tabs">
<?php print $tabs; ?></div>
<?php endif; ?>
<?php if (!empty($messages)): print $messages; endif; ?>
<?php if (!empty($help)): print $help; endif; ?>
<div id="content-content" class="clear-block">
<?php print $content; ?>
</div> <!-- /content-content -->
<?php print $feed_icons; ?>
</div> <!-- /content -->
</div>
</div> <!-- /contentInner /contentBox -->
</div>
<div id="footer">
<?php print $footer_message; ?>
<?php if (!empty($footer)): print $footer; endif; ?>
</div> <!-- /footer -->
<?php print $closure; ?>
</body>
</html>
page-blog.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" xml:lang="
<?php print $language->language ?>" lang="
<?php print $language->language ?>" dir="
<?php print $language->dir ?>">
<head>
<?php print $head; ?>
<title>
<?php print $head_title; ?></title>
<?php print $styles; ?>
<?php print $scripts; ?>
<script type="text/javascript">
<?php /* Needed to avoid Flash of Unstyled Content in IE */ ?> </script>
</head>
<body class="root
<?php print $body_classes; ?> scroller">
<div id="wrap">
<div id="header">
<div id="logo-title">
<?php if (!empty($logo)): ?>
<a href="
<?php print $front_page; ?>" title="
<?php print t
('Home'); ?>" rel="home" id="logo">
<img src="
<?php print $logo; ?>" alt="
<?php print t
('Home'); ?>" />
</a>
<?php endif; ?>
<?php if (!empty($site_name)): ?>
<h2 id="site-name">
<a href="
<?php print $front_page ?>" title="
<?php print t
('Home'); ?>" rel="home"><span>
<?php print $site_name; ?></span></a>
</h2>
<?php endif; ?>
<?php if (!empty($breadcrumb)): ?><div id="breadcrumb">
<?php print $breadcrumb; ?></div>
<?php endif; ?>
</div> <!-- /logo-title -->
<?php if (!empty($search_box)): ?>
<div id="search-box">
<?php print $search_box; ?></div>
<?php endif; ?>
<?php if (!empty($header)): ?>
<div id="header-region">
<?php print $header; ?>
</div>
<?php endif; ?>
</div> <!-- /header -->
<div id="sidebar">
<div id="navigation" class="menu
<?php if (!empty($primary_links)) { print "withprimary"; } if (!empty($secondary_links)) { print " withsecondary"; } ?> ">
<?php if (!empty($primary_links)): ?>
<div id="primary" class="clear-block">
<?php print theme
('links', $primary_links, array('class' => 'primary-links')); ?>
</div>
<?php endif; ?>
<?php if (!empty($secondary_links)): ?>
<div id="secondary" class="clear-block">
<?php print theme
('links', $secondary_links, array('class' => 'links secondary-links')); ?>
</div>
<?php endif; ?>
</div> <!-- /navigation -->
<?php print $sidebar; ?>
</div> <!-- /sidebar -->
<div id="contentBox">
<?php if (!empty($title)): ?>
<h1 class="title" id="page-title">
<?php print $title; ?></h1>
<?php endif; ?>
<div id="contentInner">
<?php if (!empty($mission)): ?>
<div id="mission">
<?php print $mission; ?></div>
<?php endif; ?>
<div id="content">
<?php if (!empty($tabs)): ?>
<div class="tabs">
<?php print $tabs; ?></div>
<?php endif; ?>
<?php if (!empty($messages)): print $messages; endif; ?>
<?php if (!empty($help)): print $help; endif; ?>
<div id="content-content" class="clear-block">
<?php print $content; ?>
</div> <!-- /content-content -->
<?php print $feed_icons; ?>
</div> <!-- /content -->
</div>
</div> <!-- /contentInner /contentBox -->
</div>
<div id="footer">
<?php print $footer_message; ?>
<?php if (!empty($footer)): print $footer; endif; ?>
</div> <!-- /footer -->
<?php print $closure; ?>
</body>
</html>
page-front.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" xml:lang="
<?php print $language->language ?>" lang="
<?php print $language->language ?>" dir="
<?php print $language->dir ?>">
<head>
<?php print $head; ?>
<title>
<?php print $head_title; ?></title>
<?php print $styles; ?>
<?php print $scripts; ?>
<script type="text/javascript">
<?php /* Needed to avoid Flash of Unstyled Content in IE */ ?> </script>
</head>
<body class="root
<?php print $body_classes; ?>">
<div id="wrap">
<h1 id="site-name">
<?php print $site_name; ?></h1>
<h2><a href="
<?php print $front_page; ?>album">相册</a>/<a href="
<?php print $front_page; ?>blog">日志</a></h2>
<div id="footer">
<?php print $footer_message; ?>
<?php print $feed_icons; ?>
<?php if (!empty($footer)): print $footer; endif; ?>
</div>
</div>
<?php print $closure; ?>
</body>
</html>