Customising full page layouts and sections

description

This section outlines and provides snippets for customising your full page layout for certain page types. Useful if you want to have different variations of your theme for different sections of your site.

Full page layouts are controlled by the page.tpl.php layout file when using the PHPTEMPLATE ENGINE.

update for Drupal 5.x

The PHPTEMPLATE Engine for Drupal 5.x has a new feature that automatically loads page-layout.tpl.php files as soon as you upload them to your active theme folder. In other words, if you upload a page-blog.tpl.php file to your active theme folder, you don't need to tell template.php.

Here's the notes from the phptemplate engine file:

Build a list of suggested template files in order of specificity. One
suggestion is made for every element of the current path, though
numeric elements are not carried to subsequent suggestions. For example,
www.example.com/node/1/edit would result in the following
suggestions:

Build a list of suggested template files in order of specificity. One
suggestion is made for every element of the current path, though
numeric elements are not carried to subsequent suggestions. For example,
www.example.com/node/1/edit would result in the following
suggestions:
 
  page-node-edit.tpl.php
  page-node-1.tpl.php
  page-node.tpl.php
  page.tpl.php

The following snippets may still be used with Drupal 5.x themes, in particular in situations where the phptemplate engine 'drops' the custom page-layout.tpl.php file.

For example, if you upload a custom page-forum.tpl.php file, the layout is 'dropped' when you're viewing a thread. Which is something you may not want.

For Drupal 4.7.x and earlier you need to instruct template.php to load a custom page-layout.tpl.php file.

usage

Scroll down for some example snippets, that you can copy-and-paste and use in your custom page-type.tpl.php layout files.

It is recommended that you use a text editor like notepad.exe, or equivalent, when editing your layout files.

For PC users, a useful tool for editing a mix of HTML & PHP is Crimson Editor (Freeware), for Mac users there is the free TextWrangler editor.

available variables

The following is a list of variables available to your custom page-type.tpl.php layout files.

  • head_title: The text to be displayed in the page title.
  • language: The language the site is being displayed in.
  • site: The name of the site, always filled in.
  • head: HTML as generated by drupal_get_html_head() (needed to dynamically add scripts to pages)
  • onload_attributes: Onload tags to be added to the head tag, to allow for autoexecution of attached scripts.
  • directory: The directory the theme is located in , ie: themes/box_grey or themes/box_grey/box_cleanslate
  • logo: The path to the logo image, as defined in theme configuration.
  • site_name: The site name of the site, to be used in the header, empty when display has been disabled.
  • site_slogan: The slogan of the site, empty when display has been disabled.
  • search_box: True(1) if the search box has been enabled.
  • search_url: URL the search form is submitted to.
  • search_button_text: Translated text on the search button.
  • search_description: Translated description for the search button.
  • title: Title, different from head_title, as this is just the node title most of the time.
  • primary_links (array): An array containing the links as they have been defined in the phptemplate specific configuration block.
  • secondary_links (array): An array containing the links as they have been defined in the phptemplate specific configuration block.
  • breadcrumb: HTML for displaying the breadcrumbs at the top of the page.
  • tabs: HTML for displaying tabs at the top of the page.
  • messages: HTML for status and error messages, to be displayed at the top of the page.
  • layout: This setting allows you to style different types of layout ('none', 'left', 'right' or 'both') differently, depending on how many sidebars are enabled.
  • help: Dynamic help text, mostly for admin pages.
  • styles: Required for stylesheet switching to work. This prints out the style tags required.
  • mission: The text of the site mission.
  • is_front: True if the front page is currently being displayed. Used to toggle the mission.
  • sidebar_left: The HTML for the left sidebar.
  • content: The HTML content generated by Drupal to be displayed.
  • sidebar_right: The HTML for the right sidebar.
  • footer_message: The footer message as defined in the admin settings.
  • closure: Needs to be displayed at the bottom of the page, for any dynamic javascript that needs to be called once the page has already been displayed.
 
 

Drupal is a registered trademark of Dries Buytaert.