drupal 开发

从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 (必须)
人类易读的名字可以在这里设定,相对于”机读”内部名而言。这里对可用字符的限制更少。
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″

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值