| Vonleigh Simmons 2004-07-21, 9:00 am |
| > i'm currently including my page "modules" with {include
> file="f00.tpl"} as suggested in the documentation, why would one use
> php in this case? my modules like header navi or footer are simple
> html anyway since they're the building blocks of my xhtml pages.
I'd do it for simplicity. I don't like including too much logic in my
smarty, since I find it easier to keep that all in the PHP. So your
template would look like:
main.tpl
--
{include file="header.tpl"}
<div id="content">
{$content}
</div>
{include file="footer.tpl"}
---
Header wouldn't be a pure xhtml file as in your case, it would have a
{$title} field so that you can set the title of the page appropriately,
you could also change the keywords and other metadata if you wanted.
Then in your PHP you can have a nice switch statement:
--
$cacheID, $pageRequest = $_SERVER['REQUEST_URI'];
if (!$smarty->is_cached('main.tpl',$cacheID)) {
switch ((string)$pageRequest) {
case "":
$smarty->assign('title','Main Page');
$content = $smarty->fetch("$siteRoot/text/Main.xhtml");
break;
case "about":
$smarty->assign('title','About Page');
$content = $smarty->fetch("$siteRoot/text/About.xhtml");
break;
default:
$smarty->assign('title','Error Page');
$conent = "some nice page with search hopefully so that
they can get what they want";
break;
}
} // cache
// index gets updated every 10 minutes
$smarty->cache_lifetime = (600);
$smarty->display('main.tpl', $cacheID);
---
Simple and that way your main page has multiple caches; I'm making the
CacheID the same as PageRequest for simplicity here, It's too late to
think up a better way of doing it. Your cache can be a month long or
even longer if your content doesn't change much.
Some people don't like this concept, I think it's called a FuseBox if
you want to look it up. I've used it for some projects, it's kind of
nice to be able to have a whole framework in any page, but it can get
messy if you're not careful. In some cases it's better to have
individual scripts. I guess the project will show which approach is
better.
Vonleigh Simmons
<http://illusionart.com/>
|