Displaying your Drupal Mission Statement on Multiple Pages

Jocelyn's picture
Tags:

While many sites don't need to utilize a mission statement, it can be useful for adding static content to your theme.

I needed to add copy to the header for a client that would appear on all pages, that they could easily edit and wouldn't involve any editing of the theme files. I immediately thought to use the mission statement that's available at admin/build/themes/settings. The only problem being that by default, the Drupal mission statement only appears on the home page.

You can add the logic to your page.tpl.php, but it's best practice to keep your site's logic separate from your design.

  1. Make sure that 'Mission statement' is checked at admin/build/themes/settings
  2. Fill out your 'Mission statement' at admin/settings/site-information
  3. Update your theme files (see below)
  4. If you are adding the function phptemplate_preprocess_page(&$vars) to your template.php file for the first time, don't forget to flush the theme registry.

template.tpl.php

<?php
function phptemplate_preprocess_page(&$vars) {
 
/**
  * Mission statement
  *
  * the mission statement (admin/settings/site-information) is only available
  * to the homepage. make it available to all pages.
  */
 
$vars['mission'] = theme_get_setting('mission', FALSE);
}
?>

page.tpl.php
Add the following to wherever you'd like the mission statement to appear. Note the id 'mission' can be changed to anything you like.

<?php
if (!empty($mission)) { print '<div id="mission">'.nl2br($mission).'</div>'; }
?>
Tags:

Comments

Mary Mary's picture

This evidently works but is also one of the occasions that I wonder about the 'drupal best practices' .

Here's what I mean. If you are building a theme then doing what you suggest makes absolute sense. Various users can input their own mission statement into your theme.

However, it makes no sense at all if you are building a single site. Why not just put the text in the page.tpl.php file? No pre-processing, no complication, no server load, no problems. Unchanging elements of the page should go in the page.tpl.php file. This bit of text is an unchanging element of the page (unless of course you envisage changing your mission statement frequently.)

Just because we have a super powerful content management system doesn't mean that we have to use it to crack even the smallest of nuts.....

Jocelyn's picture

While you could just throw the same piece of text in your page.tpl.php file, best practice would be to keep separation between your theme and your content.

Even if the text is going to be for the most part unchanging, there could come a point where it does need to change. If you've placed this text in your page.tpl.php file, you can't just login to your site and edit that copy.

Too if you've built this site for a client, they may not know (or know how) to look for this file to make an edit.

And you're really not adding any load to your site by outputting a variable.

Gabriel Radic's picture

Yep, worked as advertised. Worth adding this bit, probably commented out, to the default template.tpl.

I am using the blueprint theme myself.

Thanks :-)

Add New Comment