drupal7 与Drupal6 在主题方面有很大的变化,Drupal6 主题好多朋友比较熟悉,对于Drupal7 新主题的变化,在此和大家一起分享和交流。列举如下:
一、在html.tpl.php的开始部分RDFa请求有些变化
1.Drupal7能够在html.tpl.php.输出RDFa请求有以下变量
2.老的lang属性应该被改成compatibility with XHTML 1.1,仅仅xml:lang应该保留。
3.RDF命名前缀通过HTML文档在html标签中序列化以及被包含在$rdf_namespaces变量中。
4.GRDDL资料应该在<head> 标签内标明
6.x
<!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="" lang="<?php
print $language->language
?>" dir="<?php
print $language->language
?>"> <head><?php
print $language->dir
?>
7.x
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="" dir="<?php
print $language->language
?>"<?php
print $language->dir
?>> <head profile="<?php
print $rdf_namespaces
?>"><?php
print $grddl_profile
?>
二、删除了Box.tpl.php模板文件
之前的box.tpl.php 模板文件被删除。这部分内容现在有它们自己的函数。搜索结果列表选择仅仅用的是heme('search_results') 主题化,代替之前附加在box里。来自Box的评论主题化用theme_comment_form_box() 主题函数。
三、变量改成区域或更名
1.$help
drupal7中默认的区域(左,右,内容,头部,尾部)之外,加了一个新的帮助区域。相当于之前在drupal6下page.tpl.php 中的$help变量输出的内容。
2.$mission
被定义成'highlighted' 区域
3.$footer_message
尾部信息可以通过尾部区域来显示。在主题说明文件中输出
regions[footer] = Footer
4.$closure
变成 $page_bottom, 新的 $page_top 和隐藏区域。Drupal6中提供一个特殊的变量$closure,应该放在HTML页面BODY标签底部和可以用过theme_footer()(在模块中用hook_footer()钩子来实现)被主题化。为了在不同的页面区域统一成一种方式,drupal7在区域中标准化并且在 page_bottom区域中放置$closure特别变量。同样page_top也是以page_bottom相对应添加。在drupal7里你需要在HTML页面BODY标签顶部输出$page_top,在底部输出$page_bottom。
Drupal6 :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">... <body class=""> ...<?php
print $body_classes;
?></body> </html><?php
print $closure;
?>
Drupal7 :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"> ... <body class=""><?php
print $classes;
?>...<?php
print $page_top;
?></body> </html><?php
print $page_bottom;
?>
如果你定制区域,需要记住非常重要的一点就是在你的区域设定中包括page_top 和page_bottom 区域
theme .info file extract: regions[content] = Content regions[help] = Help regions[page_top] = Page top regions[page_bottom] = Page bottom
5.$left 和 $right 改成$sidebar_first 和$sidebar_second
6.x
<div id="sidebar-left" class="column sidebar"><?php
if (!empty($left)):
?></div> <!-- /sidebar-left --><?php
print $left;
?>...<?php
endif;
?><div id="sidebar-right" class="column sidebar"><?php
if (!empty($right)):
?></div> <!-- /sidebar-right --><?php
print $right;
?><?php
endif;
?>
7.x
<div id="sidebar-first" class="column sidebar"><div class="section region"><?php
if ($sidebar_first):
?></div></div> <!-- /.section, /#sidebar-first --><?php
print $sidebar_first;
?><?php
endif;
?><div id="sidebar-second" class="column sidebar"><div class="section region"><?php
if ($sidebar_second):
?></div></div> <!-- /.section, /#sidebar-second --><?php
print $sidebar_second;
?><?php
endif;
?>
6.$picture 变成 $user_picture, 以及CSS名称'picture' 改成 'user-picture'
Drupal6 (user-picture.tpl.php):
<div class="picture"></div><?php
print $picture;
?>
Drupal7 :
<div class="user-picture"><?php
if ($user_picture):
?></div><?php
print $user_picture;
?><?php
endif;
?>
7.$primary_links改成$main_menu,$secondary_links改成$secondary_menu
6.x: page.tpl.php
<div id="menu"><?php
if (isset($secondary_links)) {
?><?php
print theme('links',$secondary_links, array('class'=>'links','id'=>'subnavlist'));
?><?php
}
?><?php
if (isset($primary_links)) {
?><?php
print theme('links',$primary_links, array('class'=>'links','id'=>'navlist'))
?></div><?php
}
?>
7.x: page.tpl.php
<div id="menu"><?php
if (isset($secondary_menu)) {
?><?php
print theme('links',$secondary_menu, array('class'=>'links','id'=>'subnavlist'));
?><?php
}
?><?php
if (isset($main_menu)) {
?><?php
print theme('links',$main_menu, array('class'=>'links','id'=>'navlist'))
?></div><?php
}
?>
8.$taxonomy改成$terms
6.x
<div class="terms"><?php
if ($taxonomy):
?></div><?php
print $terms
?><?php
endif;
?>
7.x
<div class="terms"><?php
if ($terms):
?></div><?php
print $terms
?><?php
endif;
?>
8.在block.tpl.php中重命名$block->content 为$content。
四、CSS选择器名字改变
1. 区块的ID选择符
许多在Drupal7 核心代码中把区块的CSS ID选择符定义成更加可以明确表达区块意思的名称。
用户登录区块
老的CSS ID (Drupal6 ): block-user-0
新的 CSS ID (Drupal7 ): block-user-login
2. clear-block类选择标签被定义成 clearfix。
在Drupal6 中<div class="clear-block"> 改成<div class="clearfix">就可以了。



新浪微博
腾讯微博