In my preprocess_page() function, I'm setting variables based on the user that is logged in.

I created a custom page that is used as a Welcome page with the information about the user that I set in the variables in the preprocess_page() function.

The problem I have is that the page is not allowing me to put the print statements to echo out the variable, i.e.

<h1 style="font-size:18px; padding-bottom:3px;"><?php print $FirstName. " ".$LastName; ?></h1>

It doesn't echo out the variable values.

Also, I need later to do something based on the value of a variable. I have tried using an if statement like this:

  if($designations == 'ABCDE') {
              <td align="center" style="width: 40px;"><img src="images/abcde.png" alt=""></td>
  } else {
              <td align="center" style="width: 40px;">&nbsp;</td>

but all it does is print out part of the PHP:

if($designations == 'ABCDE') {
} else {

What am I doing wrong here???

Updated (Added preprocess_page function code):

function mix_and_match_preprocess_page(&$vars) {
  $vars['page_color'] = theme_get_setting('mix_and_match_page_bg');
  if(user_is_logged_in()) { 
    // Get the user's info and assign the values to variables.
    $vars['ParticipantID'] = 1007945;
    $vars['Username'] = 'JOESMITH';
    $vars['Password'] = 'passwd';
    $vars['FirstName'] = 'Joe';
    $vars['MiddleName'] = '';
    $vars['LastName'] = 'Smith';
    $vars['Suffix'] = '';
    $vars['PreferedEmailAddress'] = '[email protected]';
  } // if($logged_in)  

Showing new code and results: This code:

<h1 style="font-size:18px; padding-bottom:3px;"><?php print $FirstName. " ".$LastName; ?></h1>

produces (When view source):

<h1 style="font-size:18px; padding-bottom:3px;"><?php print $FirstName. " ".$LastName; ??></h1>

this code:

drupal_set_message('I got here');
<?php if($designations == 'ABCDE': ?>                
                  <td align="center" style="width: 40px;"><img src="images/cic-35x29.png" alt=""></td>
drupal_set_message('I got here');
<?php else: ?>
                  <td align="center" style="width: 40px;">&nbsp;</td>
<?php endif; ?>                

produces (When view source):

drupal_set_message('I got here');<br />
<?php if($designations == 'UACIC'): ??>
<td align="center" style="width: 40px;"><img src="images/cic-35x29.png" alt="" /></td>
<p>drupal_set_message('I got here');<br /><?php else: ??></p>
<td align="center" style="width: 40px;"> </td>
<p><?php endif; ??>
  • it would help very much if you posted here your _preprocess_page function code where you're setting those variables. Mar 6, 2012 at 20:13
  • There's a typo in your code - on the 5th line you have "</php" instead of "<?php" That could munge things up pretty good...
    – jmarkel
    Mar 6, 2012 at 20:38
  • @jmarkel, that didn't help.
    – MB34
    Mar 6, 2012 at 20:45
  • @Alex, see updated post. I'm using Mix and Match theme.
    – MB34
    Mar 6, 2012 at 20:46
  • I'd put some drupal_set_message('I got here'); style debugging in there to make sure all your logic is actually happening. Also, from a pure style and ease of reading standpoint, I'd use the <?php if(foo): ?> ////// <?php endif; ?> style in your templates instead of the {} style you have now, too.
    – Jimajamma
    Mar 6, 2012 at 21:01

1 Answer 1


Assuming you put the preprocess code in your theme's template.php, coding this inside a node ought to work - but in order for it to do so you have to

  1. make sure the Core "PHP Filter" module is enabled and
  2. make sure the node's Input Format is set to "PHP code."

As I noted, this is not the most secure or maintainable way to do things, but it'll let you do what you want without messing about in page or node templates.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.