repetitive calls to template engine
Posted: Mon Sep 05, 2005 2:16 pm
I am going to need to make repetitive calls to my template engine, across several page and I am trying to figure out the best way to avoid calling each method one by one on each page, my average call will look like this:
I was thinking instead of putting all that on every page, I could increase readability and make it easier to make site wide changes by having all the repetitive calls done by some sort of abstraction. Like I said in the comment I don't really want defaults in the template class. I could perhaps have a class that extends the template class, and that class would make all those calls for me, but that might be headed in the wrong direction? Another thing I could possibly do is have a function defined in class.php (the file I include on every page, has database connection settings, includes common class definitions, starts the session, etc...) I could write a function in there and have it make all the calls for me, the problem with that is how the function would make the calls. Would it involve passing the $template object by reference? or should I access the $template object on the global scope? But if I do the global scope thing, that would involve relying on what I named my identifier, which is 'bad practice', as I plan on using a lot of this code for a great deal of many projects in the near future.
If anyone has done something like this could you tell me the methods in which you used? Thanks for your help, hopefully I find a 'clean' way to do what I want
Code: Select all
require_once('class.php');
$template = new template('main');
$template -> setTitle('Title of my web page');
// I'm still deciding how I want to send the menu items (as an array, one by one or have a default list hard coded into the class
// but I will most likely want to keep the template class generic, and have nothing hard coded in it except the methods needed
$template -> addMenuItem('Home');
$template -> addMenuItem('About');
$template -> addMenuItem('FAQ');
$template -> addMenuItem('Portfolio');
$template -> setLoginBox(
(bool)$user -> validated()
);
$template -> header();
echo 'Hello world';
$template -> footer();
$template -> output();If anyone has done something like this could you tell me the methods in which you used? Thanks for your help, hopefully I find a 'clean' way to do what I want