淘小兔

我们可以为不同的条件创建不同的模板文件,Drupal会根据条件来判断到底来使用哪一个模板文件。创建这些模板文件要使用规定的命名规则。比如page--front.tpl.php,这是专门为首页制定的页面模板文件。也就是说,如果我们创建一个这样的文件在我们的主题里面,Drupal在生成首页页面内容的时候会使用到这个模板文件来替换默认的那个页面模板文件,也就是page.tpl.php。

区块默认使用的模板文件是 block.tpl.php,如果你想单独为某个区域里面的区块设计一个模板文件,比如说sidebar-first这个区域,我们可以创建一个page--sidebar-first.tpl.php文件放到我们的主题里面,Drupal会为所有在sidebar-first区域上面的区块使用这个模板文件。或者你可以为某个模块的区块设计模板,比如views模块的区块,我们可以创建一个block--views.tpl.php这个模板文件,Drupal会为所有的views生成的区块,应用这个模板文件。Drupal甚至可以让你为某个单独的区块设置模板文件,如果你想为某种内容类型创建模板文件,你可以使用node--内容类型的名称(如blog).tpl.php这种形式的模板文件。例如,node--blog.tpl.php这个模板文件就是为所有内容类型为blog的内容使用的模板文件。如果想为单独某个内容设计模板的话,可以使用node--内容的ID号.tpl.php这种形式去创建模板文件。还有很多的模板文件都支持这种用法,但是要记住它们并不容易。模板建议里面只有page.tpl.php,page--node.tpl.php,page--node--%.tpl.php。我们可以借助一个模板开发的辅助工具——Theme developer,来帮助我们判断在什么样的条件下去创建什么样的模板文件。

block-block-1.tpl.php源码:

<?php global $base_url; ?><?php  global $user; ?><div id="block-<?php print $block->module .'-'. $block->delta; ?>" class="toolbar-block block-<?php print $block->module ?>">  <?php if ($block->subject): ?>  <h2><span><?php print $block->subject ?></span></h2>  <?php endif;?>  <div class="content">    <?php if ($user->uid) : ?>    <ul class="toolbar">      <li class="user">[ <strong><?php print $user->name; ?></strong> ]        <ul>          <li class="profile"><a href="/<?php print $base_url ."/user/" . $user->uid ;?>">个人账户</a></li>          <li class="logout"><a class="logout" href="/<?php print $base_url;?>/logout?destination=<?php print $base_url . request_uri()?>">退出</a></li>        </ul>      </li>      <li class="content-add"><strong>发表内容</strong>        <ul>          <li class="blog"><a href="/<?php print $base_url;?>/node/add/blog">写日志</a></li>          <li class="album"><a href="/<?php print $base_url;?>/node/add/album">上传相片</a></li>        </ul>      </li>      <li class="admin"><strong>管理</strong>        <ul>          <li class="admin-content"><a href="/<?php print $base_url;?>/myContent">内容管理</a></li>          <li class="admin-comment"><a href="/<?php print $base_url;?>/admin/content/comment">评论管理</a></li>          <li class="admin-site"><a href="/<?php print $base_url;?>/admin">站点管理</a></li>        </ul>      </li>    </ul>    <?php else: ?>    <p class="toolbar logout"><a class="login" href="/<?php print $base_url;?>/user?destination=<?php print $base_url . request_uri()?>" title="站长登录">站长登录</a></p>    <?php endif; ?>  </div></div>

views-exposed-form.tpl.php源码:

<?php if (!empty($q)): ?><?php    // This ensures that, if clean URLs are off, the 'q' is added first so that    // it shows up first in the URL.    print $q;  ?><?php endif; ?><?php foreach($widgets as $id => $widget): ?><?php if (!empty($widget->label)): ?><label for="<?php print $widget->id; ?>"> <?php print $widget->label; ?> </label><?php endif; ?><?php if (!empty($widget->operator)): ?><?php print $widget->operator; ?><?php endif; ?><?php print $widget->widget; ?><?php endforeach; ?><?php print $button ?>

node-blog.tpl.php源码:

<?php global $base_url; ?><?php if ($teaser): ?><?php/*<!-- 摘要页面 -->*/?><div class="list blogList<?php if ($sticky) { print ' sticky'; } ?><?php if (!$status) { print ' node-unpublished'; } ?> ">  <h2 class="title-blog"><a href="/<?php print $base_url . "/" . $node->path ?>"><?php print $title ; ?></a></h2>  <?php if ($submitted): ?>  <div class="meta"> <?php print $submitted ?> </div>  <?php endif; ?>  <div class="node-body"> <?php print $node->content['body']['#value'] ; ?>    <?php if ($terms): ?>    <?php print $terms ?>    <?php endif;?>  </div>  <?php if ($links): ?>  <div class="links"> <?php print $links; ?> </div>  <?php endif;?></div><?php/*<!-- /摘要页面 -->*/?><?php endif;?><?php if ($page): ?><?php/*<!-- 完整节点页面 -->*/?><?php include 'node.tpl.php' ;?><?php/*<!-- /完整节点页面 -->*/?><?php endif;?>

page-taxonomy.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="/images/2021/07/19/02/2021071902115817340000." 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>

 

下载仅供下载体验和测试学习,不得商用和正当使用。

下载体验

请输入密码查看内容!

如何获取密码?

 

点击下载