tags:

views:

28

answers:

2

I want to make a really simple template engine for my site, to make it easier to add new pages and edit other ones.

I have a template.php file and a variable of $pageHeader. Then in my functions.php file I have a function called CallHeader() with this code:

function CallHeader()
{
     echo $pageHeader;
}

The problem is this does not echo the contents of $pageHeader to the page. I have included template.php in functions.php using:

include("template.php");

I have also tried setting $pageHeader to be global but nothing works. I'm trying to call this from index.php, which has functions.php included. If I set the CallHeader() function like this:

function CallHeader()
{
     echo "test";
}

It works, and echo's "test" to the page on index.php

Any help as to why I can't echo the contents of $pageHeader? Thanks

+1  A: 

you tried this and it didn't work ?

function CallHeader()
{
    global $pageHeader;
    echo $pageHeader;
}
Scott Evernden
Hehe, i posted the exact same thing.. I'll remove mine then. ;)
Tor Valamo
Thanks, worked a charm :)
Joseph
A: 
function CallHeader()
{
        echo $GLOBALS['pageHeader'];
}

global variables are a liability, not an asset. you've been warned, don't come back whining that you've shot your foot.

just somebody
Don't come running to me when you break your legs!
Question Mark