Hello,

Some people may like to know how to print the site_mission (as set in the site settings) to the front page of the theme. This will give you a message on the index page (like on drupal.org) that you can edit just by editing the site mission.

Here is the code:
<?php
//if we are looking at the index.php page with no QUERY_STRING then print the site_mission
if(substr($_SERVER["PHP_SELF"], strrpos($_SERVER["PHP_SELF"], "/") + 1)=="index.php" && !$_SERVER["QUERY_STRING"]) print variable_get("site_mission", "");
?>

Or you may want to print it in a box:
<?php
//if we are looking at the index.php page with no QUERY_STRING then print the site_mission
if(substr($_SERVER["PHP_SELF"], strrpos($_SERVER["PHP_SELF"], "/") + 1)=="index.php" && !$_SERVER["QUERY_STRING"]) print $this->box(variable_get("site_mission", ""));
?>

Mr PHP :: We Make Code

Comments

mlwhall’s picture

I cannot seem to get this to work. I took the code, added it into a new block, and set it to PHP. But get errors, do I need to put something infront of the PHP code in the Block?

----Martin----

killes@www.drop.org’s picture

For Drupal PHP blocks to work you have to

a) omit the php tags (<?php and ?>)
b) return the content.

mlwhall’s picture

For whatever reason, I just cannot get it to work :-(

----Martin----

aheld’s picture

The code depends upon the theme.

I recently added this to the bluesky theme by adding this code to the header function (about line 180)

    179     global $user;
    180     if (($user->uid == 0) && ($_GET["q"] == variable_get("site_frontpage        ", "node"))) {
    181                 $this->template->assign("site_mission", variable_get("site_mission", "EDIT THE SITE MISSION"));
    182             $this->template->parse("header.mission");
    183                 }

This assumes that there is a theme block called mission in the header block.

chadlupkes’s picture

Does that allow you to include files? I'm getting the actual code that I'm trying to use instead of what I'm actually trying to do.

http://www.democracyforwashington.com/civicspace-0.5/?q=phptest

Is that what you mean by 'return the content'?

killes@www.drop.org’s picture

You can do anything that PHP allows you in the block code. Any output, however, needs to be collected in an output string and that string has to be returned:

include('myfile');
$output = call_some_function();
return $output;
chadlupkes’s picture

I'm probably not familiar enough with PHP, but I tried a basic value assign and return, and it's just giving the code. When I add in the and , it gives no result at all. Is there a setting somewhere that I need to change to activate PHP code?

killes@www.drop.org’s picture

Sure, you have to select "PHP" as the block's mode.

chadlupkes’s picture

I double checked, and PHP is selected.

chadlupkes’s picture

<?php

$testval = "testing";

return $testval;

?>

I've tried it with and without the brackets. With gives no result at all, without gives:

$testval = "testing"; return $testval;

moshe weitzman’s picture

if(!arg(0)) {
  print variable_get("site_mission", "");
}
cnelsonakgov’s picture

I tried this in 4.2 and it didn't seem to work. Always returned FALSE.

Steven’s picture

It's better to use menu_get_active_item() and compare it to variable_get('site_frontpage', 'node').

(though in CVS/4.5, menu_get_active_item() returns a menu ID rather than the path and you need more code to resolve it to a path)

cornernote’s picture

Here is a home page module for drupal:
http://mrphp.com.au/node/1654

Mr PHP :: We Create Code
http://www.mrphp.com.au
sin’s picture

I've done it using PHPTemplate in Drupal 4.7 in page.tpl.php with code:
if (($mission)&&($is_front)) {print eval($mission); }
Mission is set in administer/settings/general and contains php code without angle brackets returning a string.