回主页

笨活儿关注Web前端和网页设计,同时兼顾用户体验,致力于将国外的优秀教程汉化,并不定期推荐免费优秀影视娱乐资源。

订阅本博客。


  • About/关于
  • Browse/浏览
  • Portfolio/作品集
  • Search/搜索

TOPICS/主题:生而享乐 网页设计 免费资源 Web前端 感受年轻 边翻译边学习More...


  • « [Drupal模板制作手册-3]子主题,结构与继承
  • WinMySQLAdmin出错的解决办法 »
发表时间:八月 10 ↓ 有话想说

[Drupal模板制作手册-4]主题的.info文件

由 慵云 发表于 前端开发 分类下  发表时间:星期天, 八月 10, 2008 22:14

从Drupal 6开始,每个主题都需要一个信息文件。这个文件必须一直在你的主题的根目录下。没有这个文件,你的主题将不会被Drupal侦测到。  .info文件必须是以”.info”为文件后缀名。

“机器” 可读的主题的[内部名]来源于这个文件。例如,如果这个文件的被命名为”drop.info”, 那么Drupal就好认为相应的主题名为”drop”。请注意不要用特殊字符,因为Drupal会在很多PHP函数中用到这个名字因此在PHP语言中命名字符串的限制也适用于这个内部名的命名。必须以字母开头,不可带空格和标点。可以使用下划线(_)但不可以使用连字号(-)。数字也是被允许的,只是不能用作首字符。

注意:

  • 警告! 和你的主题内部名相同的模块可能会造成站点无法工作。因为这可能引起函数的重复定义,而这是不被PHP允许的。你安装的所有外部组件都必须有唯一的名字。
  • .info文件的内容被换成在数据库中,所有替换或者修改这个文件并不会引起Drupal的注意。(不要将这种情况和主题注册表的缓存好混淆。)要清楚缓存,执行以下步骤:
    1. 点击位于”管理(Administer) > 站点设置(Site configuration) > 性能(Performance)”的”清除缓存数据(clear)” 按钮。
    2. 如果开启了devel区块(由模块devel提供) ,点击链接 “清空缓存(Empty cache)” 。
    3. 再次访问位于”管理(Administer) > 站点构建(Site building) > 主题(Themes)”的主题选择页面。

语法与 INI 文件类似。.info文件本质上就是一个配置主题的文本文档。该文本文档的每一行都是一个键-值对,左边是键名,右边是值。 中间再加个等号。(例如: key = value) 分号用以在行外面添加注释。某些键需要特殊的语法。添加方括号组合一系列关联的值,相当于一个“数组”。如果你并不熟悉数组,使用这种键值对时就应该保持足够的简单易懂。你可以参考Drupal中默认的.info文档,仔细阅读其中的注释信息

Drupal只懂得下列的键名(带!号的为必须设定的键值)。Drupal会为没有在.info文件中指定的键使用默认值。看看核心主题的示例。

  • name !
  • description *
  • screenshot
  • version *
  • core !
  • engine *
  • base theme
  • regions
  • features
  • stylesheets
  • scripts
  • php
name (必须)
人类易读的名字可以在这里设定,相对于”机读”内部名而言。这里对可用字符的限制更少。

name = Un tema nombre de fantasía
description (必须)
主题的简短描述。 这个名字会被显示在管理界面的主题选择页面。”Administer > Site building > themes”.

description = Tableless multi-column theme designed for blogs.
screenshot
这个可选的键值告诉Drupal哪里去找寻该主题的截屏缩略图,用于在主题选择页面显示(admin/build/themes)。如果跳过不设定,Drupal会查找改主题根目录下名为”screenshot.png”的文件。所以请当你的缩略图不是”screenshot.png”时或者你想要把缩略图放在主题根目录以外的文件夹中(如 screenshot = images/screenshot.png),才设定此项。 screenshot = screenshot.png
version (建议)
The version string will automatically be added by drupal.org when a release is created and a tarball packaged. So you may omit this value for contributed themes. However, if your theme is not being hosted on the drupal.org infrastructure, you can give your theme whatever version string makes sense. 设置你开发的主题的版本。

version = 1.0
core (必须)
指定主题使用的核心。Drupal 6之后的版本会检测组件的版本匹配指定,如果不相符或者不知道,该组件都会被禁用。DRUPAL_CORE_COMPATIBILITY常量。

core = 6.x

The drupal.org packaging script automatically sets this value based on the Drupal core compatibility setting on each release node. So people downloading packaged themes from drupal.org will always get the right thing. However, for sites that deploy Drupal directly from CVS, it helps if you commit this change to the .info file for your theme. This is also a good way to indicate to users of each theme what version of core the HEAD of CVS is compatibile with at any given time.

engine (建议)
一般情况下直接设置为phptemplate就可以了。The theme engine, which is used by the theme. If none is provided, the theme is assumed to be stand alone, i.e., implemented with a “.theme” file. Most themes should use “phptemplate” as the default engine.PHPTemplate’s job is to discover theme functions and templates for the behavior of the theme. Omit this entry only if you know what you are doing.

engine = phptemplate
base theme
当你的主题需要作为子主题来使用时,给他指定一个基础主题。Sub-themes can declare a base theme. This allows for theme inheritance, meaning the resources from the “base theme” will cascade and be reused inside the sub-theme. Sub-themes can declare other sub-themes as their base, allowing multiple levels of inheritance. Use the internal “machine” readable name of the base theme. The following is used in Minnelli, the sub-theme of Garland.

base theme = garland

More details are available on the page Sub-themes, their structure and inheritance.

regions
主题的可用“块域”。定义方法为在’regions‘后面添加方括号括起来的“机读”内部名作为键名,然后将方便人类阅读的名字作为键值。如regions[theRegion] = The region name。如果没有块域被定义,Drupal会假定下列块域可用。如果需要,你可以覆写这些值。

regions[left] = Left sidebar
regions[right] = Right sidebar
regions[content] = Content
regions[header] = Header
regions[footer] = Footer

更多细节:Blocks, content and their regions

features
在主题设定页面可以选择开关的主题特性。”features” 键控制在主题设置页面哪些特性可以设定。当你的主题没有定义某些元素的时候你就可以使用这个键值来关闭这些元素显示与否的可设置性。要停用某项设置的复选框,略过这个条目不写即可。但是,如果所有条目都不写,由于系统的默认假定,所有的复选框都会被显示出来。下面的例子显示了所有可用的设定项。.通过注释掉primary_links和secondary_links元素,相应的复选框就被禁止显示,不会被站点管理员看到。

features[] = logo
features[] = name
features[] = slogan
features[] = mission
features[] = node_user_picture
features[] = comment_user_picture
features[] = search
features[] = favicon
; These last two disabled by redefining the
; above defaults with only the needed features.
; features[] = primary_links
; features[] = secondary_links

更多细节: Custom theme settings

stylesheets
以前,默认地,主题是通过自动查找style.css文件,然后调用template.php文件中 drupal_add_css() 函数来添加额外的样式表。 从Drupal 6开始,.info文件也可以为主题添加样式表。

stylesheets[all][] = theStyle.css

更多细节在样式表一节

scripts[与stylesheets同理]
Traditionally, themes could add javascripts by calling drupal_add_js() in their template.php file. Starting in 6.x, themes can also add javascripts by adding lines to their .info file:
scripts[] = script.js
More details are available in the JavaScript & jQuery section.
php
定义主题可以支持的最低PHP版本。The default value is derived from the DRUPAL_MINIMUM_PHP constant, which is the minimum required version for the rest of core. This can be redefined for a newer version if needed. For most themes, this should not be added.
php = 4.3.3

Example .info files from core themes

Garland:
theme administration display

; $Id: garland.info,v 1.5 2007/07/01 23:27:32 goba Exp $
name = Garland
description = Tableless, recolorable, multi-column, fluid width theme (default).
version = VERSION
core = 6.x
engine = phptemplate
stylesheets[all][] = style.css
stylesheets[print][] = print.css
Minnelli sub-theme of Garland.:
; $Id: minnelli.info,v 1.7 2007/12/04 20:58:44 goba Exp $
name = Minnelli
description = Tableless, recolorable, multi-column, fixed width theme.
version = VERSION
core = 6.x
base theme = garland
stylesheets[all][] = minnelli.css
Note that everything from the line “; Information added by drupal.org packaging script on 2008-02-13″ and down is added by the drupal.org packaging script. You should never manually add the project and datestamp keys. The version key added manually (in the first section) allows sites to use your theme when taken directly from CVS.

; Information added by drupal.org packaging script on 2008-02-13
version = “6.0″
project = “drupal”
datestamp = “1202913006″

; Information added by drupal.org packaging script on 2008-02-13
version = “6.0″
project = “drupal”
datestamp = “1202913006″

你应该也会喜欢:
  1. [Drupal模板制作手册-3]子主题,结构与继承
  2. [Drupal模板制作手册-2]主题的解剖
  3. [Drupal模板制作手册-1]主题定制概述
  4. [Drpal模板制作手册-5]重写可主题化的输出
  5. 即刻提升jQuery性能的十个技巧[TUTS+]
  6. 给JavaScript新手的24条实用建议[TUTS+]
  7. 正则表达式高级技巧背后的关键概念[SM]
  8. 40个实用的轻量级JavaScript库[SM]

标签:CSS • drupal • JavaScript • jQuery • 模板

© 笨活儿   允许转载,但请以链接形式保留出处。也欢迎您使用RSS订阅本博客。

  • « [Drupal模板制作手册-3]子主题,结构与继承
  • WinMySQLAdmin出错的解决办法 »

感谢第一位留言的小朋友!

  1. sxz ←@
    十月 22, 2009 9:52 下午

    慢慢学习,感谢博主!!!

多说话有益身体健康

点击这里取消回复

请勿发表“顶”、“好”、“很有用”之类对他人没有帮助的话。欢迎针对文章内容发表您自己的真知灼见。

点击人名后面的 ←@ 可以回复TA。如果已经超过回复层级,您可以在上一级回复,并记得加上“@称呼”以注明您回复的是谁。

您可以订阅本文的RSS供稿,及时了解大家的讨论进度。


唠唠叨叨:
  • 03月07日
     以上是我比较看重的优点,也是我自己努力的方向,更是我的择偶标准。而多大程度上认同和自我要求这些则决定我愿意和某人成为多要好的朋友... 
  • 03月07日
     今天洗完澡只换了内衣内裤,而内衣内裤是一模一样的两件。突然就有买几套一模一样的外衣裤换着穿的冲动。 
  • 03月06日
     当你真的学会不带感情地看一段历史,你会发现这些历史里有的只是无可奈何的苦涩。 
  • 03月06日
     越来越觉得人性是很值得研究的东西,从人性的规律找到人存在的意义,是每个人一生都该做的功课。 
  • 03月06日
     虽然说激情的演说越来越烦人,但不得不承认,每次听他讲我都会想很多东西。我自己的价值观也更佳清晰和坚定。 

由 嘀咕 提供服务


  • 择日再见 Calendar

    2010年三月
    一 二 三 四 五 六 日
    « 十二    
    1234567
    891011121314
    15161718192021
    22232425262728
    293031  
  • 订阅 Subscribe

    • google reader
    • 抓虾
    • 鲜果
    • 有道
    • QQ邮箱
    • 哪吒
    • 九点
    • 更多方式...
  • 广告 Ads

  • 分类文章 Categories

    • Web技术 (30)
      • 交互和UE (2)
      • 前端开发 (14)
      • 网页设计 (9)
    • 外语笔记 (8)
      • 英语精译精析 (5)
    • 好康推荐 (15)
    • 娱乐至死 (33)
    • 生活琐碎 (37)
    • 设计丛谈 (5)
  • 有情博客 Blogroll

    • 个篱: 音乐媒体观察
    • Fall With Me
    • 亲泥巴

    更多

  • 热文 Hot Posts

    • 《民主的细节》免费赠送
    • Web技术要发展,IE6必须先消失!
    • 面试心得
    • 对《民主的细节》赠送活动的一点小牢骚
    • 浅谈前端新人的职业规划
    • 网页设计中的包容原则[ALA]
    • [Britain's Got Talent]英国达人2009年度冠军Diversity视频合辑

校内 | 豆瓣 | Last.Fm | Facebook | Google Reader | 百度 | 维基百科

© 笨活儿 2009

本站所有内容均可自由转载,但请遵循CC协议规定

Powered By WordPress, Original Theme by BenHuoer