Drupal 6 Custom Maintenance Pages


workinDo you follow the instructions for upgrading Drupal? If you do, you put your site into maintenance mode as part of the process. (I smile writing this because I haven’t always followed those instructions and I’m betting you haven’t always either.) It is the right thing to do though.

But that is only one reason your users might see the maintenance page. If your host has database problems, you could be showing your customers the default Drupal maintenance or offline page. Probably not the image you were looking for. This article will walk you through the process of creating custom maintenance/offline pages for your Drupal sites that will keep a profession look and feel, respecting your site design and style.

Maintenance vs. Offline

site_maint_settingsAfter reviewing a number of references on Drupal.org and finally landing on these instructions, I have concluded to following definitions.

Maintenance Mode – This mode is put in place by the site administrator via the Administer > Site configuration > Site maintenance settings on a Drupal site. Administrators can still access the site.

Offline Mode – This mode is enabled when the Drupal site is unable to connect to its database. (Think Maintenance mode without DB access) This typically indicates a significant failure of the database services.

So, maintenance mode is typically done on purpose by an administrator while an offline occurrence typically would be accidental or part of schedule maintenance. This distinction is important because in offline mode, your template needs to be able to function on its own without calling the database in order to function.

Custom Maintenance Mode Page

std_site_maint_view_minelliLet’s tackle the maintenance mode page first. The idea here is that when the administrator places the Drupal website into maintenance mode that a friendly page is served to your customers. We want our maintenance page to have a consistent look and feel with the rest of our site.

add_maint_theme_keyBy default, when you set your site offline in maintenance mode, your customers see the maintenance page from the Minelli default core theme. This is regardless of the default theme chosen for your site. This is one of the biggest sources of confusion. Drupal has this configured by default in your settings.php file.

In our case, let’s say we are using the wonderful Acquia Marina theme as the default for our site. With this in mind, we need to modify one file on our Drupal site. Navigate to your Drupal site root directory and then to the /sites/default/settings.php file and open it up.  Using your favorite editor, add the following line to the end of the settings.php file.

$conf['maintenance_theme'] = 'acquia_marina';

So, we added the configuration key ‘maintenance_theme key to our settings.php file and changed the theme value to ‘acquia_marina’.

new_maint_pageThis setting change has now told Drupal to use the acquia_marina theme for the maintenance page. So, reload your browser and refresh your site. Lucky for us, the Acquia Marina theme comes with a custom maintenance page, but if your theme doesn’t, read on.

No maintenance-page.tpl.php In Your Theme?

So, if you refresh and things look odd, Hmmm….so why does the page look like an unstyled page, not like your theme? Well, now we are on step 2. Drupal has looked at our theme for a maintenance-page.tpl.php page, however we don’t have one yet in our theme. So it’s time to created one.

There are two thoughts on how to do this. First, some folks prefer to start with the generic temple found in modules/system/maintenance-page.tpl.php while others prefer to start with their theme page.tpl.php and modifying it. Either way, you need to get a maintenance-page.tpl.php in your theme directory.

Now, theming the page itself is beyond the scope of this article but the same Drupal 6 theme concepts apply.

Maintenance Offline Mode

As we described earlier, there is not only the maintenance mode that the administrator can set, there is also an offline mode that is engaged by an inability of Drupal to connect to the database. Again, there are two ways you can address this in Drupal 6. One is in the maintenance-page.tpl.php and the other is the creation of a separate maintenance-page-offline.tpl.php.

Offline In Maintenance-page.tpl.php

If you want the same maintenance.tpl.php to serve both maintenance mode and offline mode you need to keep one thing in mind. In offline mode, Drupal does not have access to the database. Therefore, any theme template calls for data from the Drupal DB will fail.

As of the writing of this article, the Acquia Marina theme does not gracefully handle the db offline scenario in the template.php

According to the Drupal documentation:

“Any function call that depends on the database should be checked first with db_is_active. The variable $db_is_active can also be used from the template.”

Here is a slightly modified version, available for download, of the Acquia Marina template.php that takes care of the DB errors by checking for $db_is_active where necessary.

Custom Maintenance-page-offline.tpl.php

Another way to handle the offline mode specifically is to create a separate maintenance-page-offline.tpl.php file. The contents of this file will be used to render the custom offline mode page to the user. The benefit here is that your messaging can be different for an offline versus maintenance mode condition.

Personally I prefer this since access to the DB has been lost, theme settings are not available. Thus, you can hard-code, logos or such as needed in this separate file.

Conclusion

Again, Drupal gives you many options to customize your site. It just takes learning the possibilities and intricacies of the platform. We hope this article helps you better theme your maintenance and maintenance offline pages.

Blessings.

Popularity: 31% [?]

About Tom

Christ follower, husband, father, technology and photography enthusiast. Attempting to live life out as a light in this world and stumbling at times in this fallen world. Got a topic you want to have me look into? Did I miss something in a post? Let me know. Just add a comment below.