Print Mission on the Front Page

cornernote - July 1, 2003 - 03:48

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

Print Mission

mlwhall - September 5, 2003 - 16:08

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

Drupal blocks

killes@www.drop.org - September 5, 2003 - 22:44

For Drupal PHP blocks to work you have to

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

For whatever reason, I just c

mlwhall - September 7, 2003 - 19:20

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

----Martin----

What theme are you using?

aheld - September 15, 2003 - 21:06

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.

Drupal PHP Blocks

chadlupkes - August 29, 2004 - 05:48

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'?

You can do anything that PHP

killes@www.drop.org - August 29, 2004 - 05:59

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:

<?php
include('myfile');
$output = call_some_function();
return
$output;
?>

Hmm, still not working

chadlupkes - August 29, 2004 - 06:18

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

<?php
and
?>
, it gives no result at all. Is there a setting somewhere that I need to change to activate PHP code?

Sure, you have to select "PHP

killes@www.drop.org - August 30, 2004 - 18:49

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

Yep, PHP

chadlupkes - August 31, 2004 - 03:23

I double checked, and PHP is selected.

Here's the code I'm using:

chadlupkes - August 31, 2004 - 03:27

<?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;

simpler (untested)

moshe weitzman - September 7, 2003 - 21:13

if(!arg(0)) {
  print variable_get("site_mission", "");
}

Doesn't seem to work

Curtis Nelson - October 2, 2003 - 23:51

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

menu_get_active_item()

Steven - August 29, 2004 - 16:01

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)

Heres a front page module...

cornernote - January 6, 2005 - 04:24

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

Mr PHP :: We Create Code
http://www.mrphp.com.au

How to print mission containing php code to front page

sin - January 7, 2006 - 17:17

I've done it using PHPTemplate in Drupal 4.7 in page.tpl.php with code:

<?php
if (($mission)&&($is_front)) {print eval($mission); }
?>

Mission is set in administer/settings/general and contains php code without angle brackets returning a string.

 
 

Drupal is a registered trademark of Dries Buytaert.