I'm in the process of creating a drupal site using the Zen theme (which I've modified) and want to utilize the mission statement. Right now, the Mission Statement is checked and shows up on the front page, and the front page only. I want this to show up on every page. Below is my current code in the page.tpl.php file:

...
<div id="banner">
<?php if ($mission): ?>
<div id="mission">
<?php print $mission; ?>
</div>
<?php endif; ?>
...

I want to leave drupal's functionality in tact, meaning if the Mission Statement is checked it shows up on every page, but if it isn't checked, it wouldn't show up on any page. Now I'm not a PHP guru by any stretch of the imagination, but the above code seems like it checks to see if the Mission Statement box is checked and if so it "prints" it to the page. I just can't figure out why it only does it to the front page. I could not find any other reference in the mission statement. Is there an "isfront" constraint somewhere else that i'm missing? if so, it's not in the page.tpl.php file.

Any help is greatly appreciated.

:cD

Comments

vm’s picture

inspect your template.php ?

STyL3’s picture

Not sure exactly what I'd be looking for, but I don't see any references to the mission statement. However, my noobness tells me that the $body_classes[] are playing a part. Below you will find the code in my page.tpl.php and template.php files.

page.tpl.php

<body class="<?php print $body_classes; ?>">
<div id="page">
  ...
      <div id="banner">
           <?php if ($mission): ?>
                <div id="mission">
                     <?php print $mission; ?>
                </div>
           <?php endif; ?>
      </div>
    ...
</div>
</body>

template.php

function _phptemplate_variables($hook, $vars = array()) {
  switch ($hook) {
   ...   
      $body_classes = array();
      // classes for body element
      // allows advanced theming based on context (home page, node of certain type, etc.)
      $body_classes[] = ($vars['is_front']) ? 'front' : 'not-front';
      $body_classes[] = ($vars['logged_in']) ? 'logged-in' : 'not-logged-in';
      if ($vars['node']->type) {
        $body_classes[] = 'ntype-'. zen_id_safe($vars['node']->type);
      }
      switch (TRUE) {
      	case $vars['sidebar_left'] && $vars['sidebar_right'] :
      		$body_classes[] = 'both-sidebars';
      		break;
      	case $vars['sidebar_left'] :
      		$body_classes[] = 'sidebar-left';
      		break;
      	case $vars['sidebar_right'] :
      		$body_classes[] = 'sidebar-right';
      		break;
      }
      // implode with spaces
      $vars['body_classes'] = implode(' ', $body_classes);
      
      break;
      
    case 'node':
      // get the currently logged in user
      global $user;

      // set a new $is_admin variable
      // this is determined by looking at the currently logged in user and seeing if they are in the role 'admin'
      $vars['is_admin'] = in_array('admin', $user->roles);
      
      $node_classes = array('node');
      if ($vars['sticky']) {
      	$node_classes[] = 'sticky';
      }
      if (!$vars['node']->status) {
      	$node_classes[] = 'node-unpublished';
      }
      $node_classes[] = 'ntype-'. zen_id_safe($vars['node']->type);
      // implode with spaces
      $vars['node_classes'] = implode(' ', $node_classes);
      
      break;
    ...
  }
  
  return $vars;
}
gpk’s picture

Try something like this:

In template.php (create it if necessary) add a function _phptemplate_variables() thus:

function _phptemplate_variables($hook, $vars = array()) {
  // Make custom variables available to theme templates
  switch ($hook) {
    // Send new variable $custom_mission to page.tpl.php
    case 'page':
      $vars['custom_mission'] = variable_get('site_mission', '');
      break;
  }
  return $vars;
}

Then in page.tpl.php use $custom_mission, which will be available on every page.

gpk

----
www.alexoria.co.uk

STyL3’s picture

This worked to perfection, thank you!

gpk’s picture

:-)

gpk
----
www.alexoria.co.uk

gigfish’s picture

where in the page.tpl.php file should i input the code
$custom_mission

and is this the complete code for that file?

gigfish

gareth_w’s picture

Would changing

...
<div id="banner">
<?php if ($mission): ?>
<div id="mission">
<?php print $mission; ?>
</div>
<?php endif; ?>
...

to

...
<div id="banner">
<div id="mission">
<?php print $mission; ?>
</div>
...

Not force it to always print, regardless?

vm’s picture

He still wants control over it in the admin area, which your method would take away.

gpk’s picture

1. That wouldn't make $mission appear on pages where it currently doesn't ... it would simply mean that an empty <div id="mission"> is output when $mission is the empty string

2. IIRC most themes only populate $mission when on the front page

gpk
----
www.alexoria.co.uk

darumaki’s picture

Is there a way to replace the mission with something else when switching to other pages ?

ie front page = mission , all other pages = other content

vm’s picture

http://drupal.org/node/104316

create a page-front.tpl.php which will include the mission statement

then remove it from page.tpl.php, or use an if else statement to remove it.

gigfish’s picture

Hi great it seems u found a solution - for not teckie types like me can u tell me what code i should paste into the page-front.tpl.php file

much appreciated.

gigfish

vm’s picture

read page.tpl.php and find the references to mission

should be something like

<?php if ($mission): ?>
                <div id="mission">
                     <?php print $mission; ?>
                </div>

though if you are using a 3rd party threme it could be a bit different

smckillop’s picture

Exactly what I needed for my theme! I'm guessing that Drupal core empties the $mission variable on pages other than the front page. Worked like a champ!

gpk’s picture

>I'm guessing that Drupal core empties the $mission variable on pages other than the front page.
Correct. $mission is defined at the top of this function http://api.drupal.org/api/function/phptemplate_page/5.

gpk
----
www.alexoria.co.uk

d1b1’s picture

Hi, I am new to drupal, but I think I have a very quick and easy solution. I had the same issue. When I tried to get the template.php hook working it did not solve the mission issue. So I added the following directly to the page.tpl.php file.

print variable_get('site_mission', '');

There must be a reason why this is not the 'drupal' way, but it works like a charm.

blackwinter’s picture

This doesn't work in drupal 6 :(

Mark Nielsen’s picture

For Drupal 6, this works:

print theme_get_setting('mission');

In fact, I'm using this, to ensure the mission statement is clean:

  print filter_xss(theme_get_setting('mission'));

(read more on filter_xss and filter_xss_admin)