Displaying your Drupal Mission Statement on Multiple Pages

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

Thoughts

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.....

Re: Thoughts

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.

Thanks

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 comment

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags
  • Lines and paragraphs break automatically
  • Websites and email addresses turn into links automatically

jsfwd on Twitter 

  • 13 hours 12 min ago hot damn rock vs rap!! thanks json RT @jswaby: @jsfwd http://www.sfspodcast.com rock vs rap
  • 13 hours 26 min ago #Raptors taking 5th seed back tonight! (with a little help from Boston)
  • 1 day 17 hours ago Two screens are better than one. I want. RT @BeCircle Yeah - iPad pwned by Courier. Way cooler and way more useful. http://bit.ly/aO4DqS
  • 4 days 18 hours ago World's largest gummy bear?!? http://www.giantgummybear.com I want one!
  • 5 days 21 hours ago Firefox 3.5 supports the word-wrap CSS property, finally :)
  • 6 days 12 hours ago Has anyone using #drupal and #mollom had any spam problems after upgrading from 6.x-1.10 to 6.x-1.12?
  • 6 days 12 hours ago @mollom has been almost flawless at blocking spam, but now cleaning uber-spam that started after upgrading the drupal module to 6.x-1.12.
  • 2 weeks 1 day ago February Drupal Toronto Meetup tonight... Topic: 'All about hosting' http://bit.ly/d8xM20
  • 2 weeks 5 days ago Since my earlier tweet re: http://pleaserobme #foursquare I've received over 7000 new opportunities! Who says there's a recession?
  • 2 weeks 5 days ago Tweeting your location can be hazardous to your home http://pleaserobme.com #foursquare
more jsfwd on Twitter »
i heart Drupal