Forum Moderators: coopster
New to php, I found that jatar_k's post was very clever about echo-ing the template:
by the same token you can also put the header and footer code into a single page called template.php with
echo $content;in the middle. Then you just do this on every page.
$content = "pathtocontentpage.html";
include "template.php";and voila, the template echo the page set to content.
However, upon attempting this, I find that all I can do is echo the literal string that I put into $content. For instance, if I said
$content = "pathtocontent.html"
what would appear in my pages is
pathtocontent.html
Any help on this? Apologies for possibly posting in the wrong place. Futher apologies for being such a newbie.
$content='This is the content of the page';
To get what was descripted simply change:
echo $content;
to
@include $content;
ps. the "@" simply surpresses errors if $content file is not found. I'd suggest something a little smarter like:
if(!@include($content) ) {
echo "I'm sorry this was not found";
}
or something like that.
daisho.
In the so called template(.php), if I were to say
@include $content;
and then in the page I wish to place content I said
$content="thispage.php";
include "template.php";
Would this not lead to an endless cycle? As in, you go to thispage.php, which includes template.php, but template.php again includes thispage.php which includes.... do you see my point? Could you possibly elaborate?
I am amazed at your fast responses. Thanks for explaining!
You have template.php that includes $content
You then have $default.php that does:
$content='thefile.php';
include $template.php;
If this is the way you are going to do things then I'd recommend splitting template into a header.php and footer.php (everything before and then everything after the content.)
Then in default.php do:
<?include 'header.php';?>
This is my content...
<?include 'footer.php';?>
The real advantage to the first template design described is if you pass the content file as a parameter ie:
[example.com...]
Then template.php will include the file pointed to by the content variable at the appropriate time.
Sky is the limit. All depends on what you like best for what you are doing.
Daisho.