Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Unfortunately, bad things sometimes happen to good Web sites, and the Web sites have to go offline. Drupal provides a default template when a connection cannot be made to the database. In addition, the site can be directed to enter “maintenance” mode so that you can perform some upgrades or other feature enhancements. Figure 4.9 and Figure 4.10 show the default templates for these two offline pages.
The offline message template will appear only to visitors who are not authenticated; administrators will still have access to the Web site as they perform their upgrades when a site is “under maintenance.” To customize these pages, complete the following steps:
1. | Copy the default maintenance page from the Drupal core directory modules/system/maintenance-page.tpl.php to your theme’s directory. |
2. | Make a second copy of the file for the offline template and name it maintenance-page-offline.tpl.php. |
3. | You should now have two new files in your theme’s directory:
|
4. | Adjust these two new templates to suit your needs. |
5. | Open your site’s configuration file in a text editor. (This file is found in sites/yourdomainname.com/settings.php. It is not a theme file, and it is probably write-protected.) |
6. | Remove the # symbol from the following lines: • Line 173: # $conf = array( • Line 175: # 'theme_default' => 'your_theme_name' • Line 187: # 'maintenance_theme' => 'your_theme_name' • Line 214: # ); |
7. | Save the changes and make the file read-only again. |
The next time you put your Web site into maintenance mode (or if your database server ever goes offline), you will be able to show your customized apology to the world instead of the default Drupal “maintenance” message.
In the section “Custom Front Page,” you learned how to create a custom front page template. The template was activated when the current page was the front page of the Web site. You may take advantage of this technique to target other types of pages as well. Page templates are activated according to Drupal’s internal path for the current page.
Internal path and URL alias
|
| This technique works only with the internal path for a page. You cannot use URL aliases. You will learn how to work with aliases in the next section. For now, you may only use paths that are related to Drupal core terminology. For example, node/5 and node/5/edit are both internal paths that can be tied to a specific page template, whereas books/fiction/story-about-ping is a URL alias. Use the Devel module to obtain a list of suggested template files for each page. If none of the suggested templates matches your needs, consider skipping ahead to the next section to discover alternative ways to create template files. |
Drupal looks through a list of suggested templates from most specific to least specific and checks your theme’s directory for a matching template file. Once it finds a template that matches the criteria, it applies that template to the page. The following list gives examples of the templates that would match for each of the pages:
page-node-5.tpl.php
page-node.tpl.php
page.tpl.php
http://www.example.com/node/5/edit
page-node-edit.tpl.php
page-node-5.tpl.php
page-node.tpl.php
page.tpl.php
http://www.example.com/books/fiction/story-about-ping
page-node-2665.tpl.php
page-node.tpl.php
page.tpl.php
The last item in the list is using a URL alias. There is not a single template that can be used by default to match any of the words in the URL to assign a template. Instead, you must know the exact node ID for the page to find a node-specific template match. These template suggestions exist automatically, so use them whenever you need to create a new template with the same file name and then theme it according to your needs. You may also need to clear the theme registry to see your new template in action.