Saturday, October 9, 2010

Creating user-defined regions in Drupal 6 themes

Previously I in the fall custom regions in Drupal to create 5 themes. However, Drupal 6 introduced a new process for creating custom themes and regions is still one of the topics, the folks over at the frequently asked questions.

So, here is a tutorial for creating custom regions in your Drupal 6 Themen.In this example will I use the Garland theme and put a new region called 'Uber content', which I about what to place in the main content area.

Custom Drupal 6 theme region

It is basically a two-step process:

Step 1 - define the custom region in your theme .info file step 2 - Insert, some PHP in your theme page.tpl.php file wherever you want to display the new region

Step 1 - define the user-defined region in your theme .info file

All Drupal 6 themes contain a .info Datei.Dies is a required element in Drupal Drupal 6 themes allows you to "See your theme".

The .info file for your Drupal 6 theme will be located in the root of the theme main folder.
Garland's .info theme file is as under:

(while a non-core .info topic will (should)) are:

/Sites/All/themes/mytheme/mytheme.info

(' S ' should be named actual replaces your theme e.g. Acquia_marina)

So, let's open Garland's .info file (garland.info) it contains the following:

; $ Id: garland.info, v 1.5 2007 / 07/01 23: 27: 32 GOBA exp $
Name = Garland
Description = tableless, recolorable, multi-column, fluid width theme (the default).
Version = VERSION
Core = 6.x
Engine = Phptemplate
Style sheets [all] [] = style.css
Style sheets [print] [] = print.css

Information packaging script added by drupal.org, on 2009-04-30
Version = "6.11"
Project = "drupal"
Stamp = "1241050838"

The first thing we want to check is whether all regions already file defined .info in our topic's.

Regions are defined as:
Regions [RegionName] = name of the region

We can see that it no regions in Garland's .info file definiert.Allerdings there regions of our blocks in garlands blocks admin interface (admin/build/block) to the Verfügung.Also whats the deal? well, unless otherwise indicated in the .info file, all Drupal 6 topics contain a number of standard regions - namely: left sidebar right sidebar, content, header and Fußzeile.Ist such an issue.

We're going to change that! we want to declare a new topic region in the .info file:

Regions [Ubercontent] uber content =

However, while add only this line in our .info file is the Ubercontent region successfully declare it will wipe out default all regions and lead to warnings on the blocks page:

Drupal 6 warning messages

Instead we all need when declaring a new region for the first time on the theme .info file standard regions and the new region deklarieren.Also we must add:

Regions [links] = left sidebar
Regions [right] = right sidebar
Regions [content] = content
Regions [header] header =
Regions [footer] = footer
Regions [Ubercontent] uber content =

The theme .info file that us final .info from:

; $ Id: garland.info, v 1.5 2007 / 07/01 23: 27: 32 GOBA exp $
Name = Garland
Description = tableless, recolorable, multi-column, fluid width theme (the default).
Version = VERSION
Core = 6.x
Engine = Phptemplate
Style sheets [all] [] = style.css
Style sheets [print] [] = print.css

Regions [links] = left sidebar
Regions [right] = right sidebar
Regions [content] = content
Regions [header] header =
Regions [footer] = footer
Regions [Ubercontent] uber content =

Information packaging script added by drupal.org, on 2009-04-30
Version = "6.11"
Project = "drupal"
Stamp = "1241050838"

Empty the cache

Long story short, if we change the topic a Drupal 6 .info file we need to clear the cache for these changes werden.Zwei found easy ways to do this:

Navigate to the site admin 'Performance' page (admin/settings/performance), scroll to the bottom titled ' clear cached data 'and click on the button' clear cached data ' select the block that generates it, and within this block will install the devel module it "empty cache ' link, click, can"

When empty the cache should you get, say a success message, delete cache.
Now we're ready for step 2.

Step 2 - Add some PHP in your theme page.tpl.php file, where ever you want to display the region

This step is still the same as for user-defined regions in Drupal 5 themes.

Open your theme page.tpl.php file and determine where they appear the new custom region to. in Garland we will our Ubercontent region above all of the other main content to do so einfügen.Um, we open garlands page.tpl.php file and locate the following code (lines 66-67):

...


...

then we have our add new code:

the result is:

...



...

Save and we are fertig.Inhalt can in our new uber content-region now successfully added and displayed.

Custom Drupal 6 theme region

Custom Drupal 6 theme region

Further reading

For more information about the .info you should check out theme, especially the Guide, Drupal 6:


View the original article here

No comments:

Post a Comment