Forum Moderators: coopster
<?php
/*These are the dynamic values that we want to insert into our template(s).*/
/*head1.inc contains Doc statement contents of <html>and Link Rels/imports thru </head>*/
$output->head = file_get('includes/head.inc');
/*logo.inc contains all logo text and images */
$output->body = file_get('includes/logo.inc');
/*topnav.inc*/
$output->body = file_get('topnav.inc');
$output->body = file_get('leftnav.html');
?>
/*Body content begins*/
<div id="content">
<h1>Hello World</h1>
</div>
<div id="right">
<!-- Content of right column -->
</div>
<?php
$output->body = file_get('includes/footer.inc');
?>
<?php
/*
This is how we merge the $output variable with the various includes
*/
echo merge_template(file_get('main_template.html'),$output);[b]/* I am stalled at this point...assuming that I am correct at this point.*/[/b]
/****************************************************
*
* Function library for using basic templates
*
*****************************************************/
/*
*file_get()
*
*Load file contents and return as a single variable
*/
function file_get($path)
{
$file = '';
$fp = fopen($path,'r');
while(!feof($fp))
$file .= fgets($fp,4098);
return $file;
}
/*
*merge_template()
*
*Merge main_template with values stored in $output object
*(note: template is always loaded in the form of a variable)
*/
function merge_template($content,$output)
{
/* Convert all the php variables to their dynamic values */
eval("\$content = \"" . str_replace("\"","\\\"",$content) . "\";");
/* Return the merged main_template from this function */
return $content;
}
?>
I would suggest looking into doing this same thing with the include command and heredoc syntax.
Example
/*include.php*/
<?
$top = <<<END
anything you have in head.inc
END;
$topnav = <<<END
anything you have in topnav.inc
END;
etc..
?>
then on your page all you do is this:
<?
include("include.php");
echo $top;
echo $topnav;
etc..
?>
Content stuff here
<?
echo footer
?>
Much easier in my opinion.
I would suggest looking into doing this same thing with the include command and heredoc syntax.
Example
/*include.php*/
<?
$top = <<<END
anything you have in head.inc
END;
$topnav = <<<END
anything you have in topnav.inc
END;
etc..
?>
then on your page all you do is this:
<?
include("include.php");
echo $top;
echo $topnav;
etc..
?>
Content stuff here
<?
echo footer
?>
Much easier in my opinion.
<?php
/*this does not work
$head = <<<END aainc-head.inc END;
?>
<?php
/*this does not work
$head = <<<END
aainc-head.inc
END;
?>
<?php
include("include.php");
echo $head;
echo $logo;
echo $topnav;
echo $leftnav;
echo $right;
?>
Still working on syntax.
I have checked php_net.
Searching for 'heredoc syntax'...
Nothing specific found ...except whitespace warning and
end of line info...that probably does not apply.
---------
[b]
/* error in browser window source code */
<br />
<b>Parse error</b>: parse error, unexpected T_SL in <b>/home/httpd/vhosts/mysite.com/httpdocs/xarahost/include.php</b> on line <b>13</b><br />
Hello World
---------
/* error in browser window */
Parse error: parse error, unexpected T_SL in /home/httpd/vhosts/mysite.com/httpdocs/xarahost/include1.php on line 13
Hello World [b]
/* include.php */
[/b]
<?php
$html = <<<END
<html>
<head>
<title>Sportsmen Afield >
<?php
echo($title);
?></title>
</head>
END;
?>
<?php
$body = <<<END //This is line 13
<body>
echo Hello World
END;
?>
<?php
$footer = <<<END
Copyright © 1998-2002 - Mysite.Com/Mysitename All Rights Reserved -
<a href="mailto:info@sportsmenafield.com"style="color:beige">Webmaster</a>
</body></html>
END;
?>
[b]
/**** index.php***/
[/b]
<?php
include("include.php");
echo $html;
echo $body;
?>
Hello World
<?
echo $footer;
?>