Suppose you have a complicated website with several different webpages that all look kinda similar..
To keep the site managable it would be neat if you could use templates of often used pieces of html so you only have to make the structure of a certain website or table once and use that in a lot of different webpages..
In many PHP supportsites this is discussed and often they advise something like this:
--
<?php
include("htmlheader.inc");
{actual content}
include("htmlfooter.inc");
?>
I'm guessing this won't be a problem if it's just 2 template files you are using.. But suppose you want to template several pieces of html you use in your pages? Won't the above approach make the whole thing incredibly slow? PHP would have to open several different files to form a single page and I'm thinking that opening/writing files is one of the slowest things you can do in a PHP script..
What do you experts think of the following approach?
--
<?php
require("templates.inc");
htmlheader();
tableheader();
{actual content}
tablefooter();
htmlfooter();
?>
This way, PHP only has to open 1 file which contains all pieces of html you wish to use often in the form of functions.. This file would look something like this:
--
<?php
function htmlheader() {
echo <<<EOT
<body>
..bla..
EOT;
}
function htmlfooter() {
echo <<<EOT
..bla..
</body>
EOT;
}
?>
Good idea?.. Bad idea?.. Stupid idea?.. Suggestion for improvement?.. Please let me know..
Kind regards,
Edwin
edwin@ultranza.com