Drupal 7 – .info file contents

The syntax of the .info file is similar to INI files. The .info file is basically a static text file for configuring the theme. Each line in the text file is a key-value pair with the key on the left and the value on the right, with an “equals sign” between them. (example: key = value) Semicolons are used to comment out a line. Some keys use a special syntax with square brackets for building a list of associated values, referred to as an “array”. If you are unfamiliar with arrays, using them should be apparent enough by following the example of the default .info files that come with Drupal and reading the explanations of the examples that follow.

Theme name requirements

The name should start with an alphabetic character, can contain numbers and underscores, but not hyphens, spaces or punctuation. The name will be used by Drupal in forming variousfunctions in PHP and therefore it has the same limitations. Warning! Do not choose the same name as a module, as all installed components must have unique names. For locally created themes using a prefix that is likely to be unique is good for theme naming. A site example.com might call its themes ex_themename.

Because the .info file is cached, you must clear the cache before any changes are displayed in your site.

The .info file can also specify which theme settings should be accessed from the Drupal administration interface, as you will soon see.

Drupal understands the keys listed below. Drupal will use default values for the optional keys not present in the .info file. See the examples set for core themes.

name (required)
The human readable name can now be set independently from the internal “machine” readable name. This imposes fewer restrictions on the allowed characters. 

name = A fantasy name

 

description (recommended)
A short description of the theme. This description is displayed on the theme select page at “Administer > Site building > themes”. 

description = Tableless multi-column theme designed for blogs.

 

screenshot
The optional screenshot key tells Drupal where to find the theme’s thumbnail image, used on the theme selection page (admin/build/themes). If this key is omitted from the .info file, Drupal uses the “screenshot.png” file in the theme’s directory.Use this key only if your thumbnail file is not called “screenshot.png” or if you want to place it in a directory outside of your theme’s base directory (e.g. screenshot = images/screenshot.png).

 

screenshot = screenshot.png

 

version (discouraged)
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 (required)
From 6.x onward, all .info files for modules and themes must indicate what major version of Drupal core they are compatible with. The value set here is compared with theDRUPAL_CORE_COMPATIBILITY constant. If it does not match, the theme will be disabled. 

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 git, 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 git is compatible with at any given time.

engine (required in most cases)
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
The block regions available to the theme are defined by specifying the key of ‘regions‘ followed by the internal “machine” readable name in square brackets and the human readable name as the value, e.g., regions[theRegion] = The region name.If no regions are defined, the following values are assumed.

Drupal 6 default regions:

 

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

 

Drupal 7 default regions:

 

regions[header] = Header
regions[highlighted] = Highlighted
regions[help] = Help
regions[content] = Content
regions[sidebar_first] = Left sidebar
regions[sidebar_second] = Right sidebar
regions[footer] = Footer

 

You can override the values for your specific needs.

More details are available on the page Blocks, content and their regions.

features
Various page elements output by the theme can be toggled on and off on the theme’s configuration page. The “features” keys control which of these check boxes display on the theme’s configuration page. This is useful for suppressing check boxes for elements not defined or used by a theme. To suppress a check box, omit the entry for it. However, if none are defined, all the check boxes will display due to the assumed defaults.The example below lists all the available elements controlled by the features key.

Drupal 6 features

By commenting out the primary_links and secondary_links elements, their check boxes are suppressed and are not seen by site administrators.

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

 

Drupal 7 features

 

features[] = logo
features[] = name
features[] = slogan
features[] = node_user_picture
features[] = comment_user_picture
features[] = favicon
features[] = main_menu
features[] = secondary_menu

 

More details are available on the page Custom theme settings.

stylesheets
Traditionally, themes default to using style.css automatically and could add additional stylesheets by calling drupal_add_css() in their template.php file. Starting in Drupal 6, themes can also add style sheets through their .info file. 

stylesheets[all][] = theStyle.css

 

Starting in Drupal 7, themes no longer default to using style.css if it is not specified in the .info file.

More details are available in the style sheets section.

scripts
Traditionally, themes could add Javascripts by calling drupal_add_js() in their template.php file. Starting in 6.x, if a file named script.js exists in the theme directory then it is automatically included. However, in Drupal 7, this behavior has been changed again so that script.js is only included if it has been specified in the .info file. Themes can also add specific javascript files by adding lines to their .info file: 

scripts[] = myscript.js

 

More details are available in the JavaScript & jQuery section.

php
This defines the minimum PHP version the theme will support. 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:

 

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
; Information added by drupal.org packaging script on 2008-02-13
version = “6.0”
project = “drupal”
datestamp = “1202913006”

 

Minnelli sub-theme of Garland.:

name = Minnelli
description = Tableless, recolorable, multi-column, fixed width theme.
version = VERSION
core = 6.x
base theme = garland
stylesheets[all][] = minnelli.css
; Information added by drupal.org packaging script on 2008-02-13
version = “6.0”
project = “drupal”
datestamp = “1202913006”

 

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 git.

Login or register to post comments

Comments

 

Naively, I assumed that I could add a link to the Google Analytics script by adding this line to my theme’s .info file:

scripts[] = http://www.google-analytics.com/urchin.js

Sadly, this will not work. It took me a long time to track down the problem, but it appears that when Drupal loads the .info file into a theme object during initialization, it renders the above line like this:

["http://www.google-analytics.com/urchin.js"] => "themes/Nefertari/http://www.google-analytics.com/urchin.js"

Note the “themes/Nefertari/” part in front of the URL. Subsequently, Drupal recognizes that the URL is malformed and drops it, so that no trace of the line from the info file winds up in the completed HTML. It took me over an hour to wade through the execution flow to find this out.

Furthermore, it appears that you can’t use drupal_add_js() in your template.php file either, because it can’t handle external JavaScript files in 6.x. People have been working on this issuefor about 13 months now, and it looks as though they might conceivably get it fixed in Drupal 7.

In the meantime, your options for linking to external JavaScript files are limited. You can:

  1. Download a copy of the file, put it in your theme folder, and then you can use your .info file to link to it. Of course, you’ll then be stuck updating the script every time the original one on the other domain changes.
  2. Hard code it into your theme.
  3. Create a custom template file for your theme and load it using a preprocess function.

I’ve opted for the third method. First I created a file called external-js.tpl.php in my theme directory, containing this:

 

<?php
<script type="text/javascript" src="http://www.google-analytics.com/urchin.js"></script>
?>

 

Then, in my template.php file, I created a pre-process function that loads that into a variable and adds the appropriate JS function call to $footer:

 

<?php
function Nefertari_preprocess_page(&$vars){
$path = drupal_get_path('theme', 'Nefertari');
$vars['external_js'] = theme_render_template($path.'/external-js.tpl.php', $vars);
$vars['footer'] .= '<script type="text/javascript">    _uacct = "UA-GOOGLE-ID"; urchinTracker(); </script>';
}
?>

 

Lastly, I modified page.tpl.php to print the variable $external_js right after $script in the header. I could also have printed it right before the footer, and that might have been better for performance. There’s actually a module for Google Analytics already, but it doesn’t fit my needs very smoothly (it’s designed for single sites, when I’m working with a multi-site install of nearly a hundred distinct Drupals).

 

QR Code
0 antwoorden

Plaats een Reactie

Meepraten?
Draag gerust bij!

Geef een antwoord

Het e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *

Deze site gebruikt Akismet om spam te verminderen. Bekijk hoe je reactie-gegevens worden verwerkt.