Setting a Warning message in the Page.tpl.php file I'm trying to set a warning message based on a PHP if statement in my page.tpl.php file. I can get a message out using $messages but I cannot using drupal_set_message(). Should I be using the latter before page.tpl.php?

The problem is the $messages variable comes out as plain text, I'd like to use Drupal's message system if possible:

drupal_set_message(t('Don\'t panic!'), 'warning');
$messages = t('Don\'t panic!');
If you want to use Drupal's message system, and you want to do this at the theme-level, as opposed to writing a module, you would enter the code

drupal_set_message(t('Don\'t panic!'), 'warning');


into your theme's template.php file as a preprocess function.  For instance, if you wanted to display this message on all content of the type 'page'

function YOURTHEME_preprocess_node(&amp;$variables) {
 if ($variables['node']-&gt;type = 'page') {
  drupal_set_message(t('Don\'t panic!'), 'warning');
 } 
} 


It should then automatically show up in the $messages area whenever someone visits a 'page' content type.

Note: You might also need to flush your theme cache after making these changes.