Ryan A wrote:
Hi,
A pal of mine needed some help on his project, he is
using a "header" and "footer" file to "template" his
project... but its gotten a bit complicated as he has
a few dynamic parts in the header and footer files, so
I told him to go with a proper templating method of
templating the whole page rather than includ()ing the
top and bottom.
This somewhat a "religious" issue for some, but my personal opinion is
that PHP is often very good at being a simple template system. Just
assign your variables beforehand, and display them with the <?= $var ?>
tag. (I do this with entire pages, split up into chunks for various
parts of content.)
I.e. template_head.php:
<?php
<html>
<head>
<title><?= $page_title ?>
<?php foreach ($css_files as $fn) { ?>
<style type="text/css">@import "<?= $fn ?>";</style>
<?php } /* end foreach ($js_files) */ ?>
</head>
<body>
?>
etc...
Then your page would look like:
<?php
/* Assign some variables */
...
include('template_head.php');
/* A little workhorse code, assign some more variables */
...
include('template_content1.php');
/* Assign even more variables */
...
include('template_foot.php');
After having a better look at his scripts, I am just
not sure if something big (like SMARTY for instance)
would be good for him. He just needs maybe 5 template
pages, same pages, different color.
Smarty is also excellent. (I still prefer pure PHP though. :-)
Searching google I see literally hundreds of
"templating solutions" can anyone recommend a simple
one or should I tell him to just use str_replace() for
tags like: {{menu_here}} {{header_here} etc?
Something like SMARTY would be like using a nuke to
kill a fly (IMHO) esp since this project will not
expand to anything much bigger or complicated.
Why kill performance when you don't have to?
jon
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php