Re: [PHP] Another Template Engine (code)
You may want to take a look at Dreamtime's template engine. I've had pretty good feedback on it so far. The template language supports things like loops, if-then, pre-compiling templates, etc., which makes assembling complex pages pretty easy. We replaced a whole heap of Cold Fusion code with a few Dreamtime templates and a little PHP code during a big conversion job (CF -> PHP) late last year. For example, if you've got a few arrays of values and want to output an HTML table, your PHP code looks like: $names = array("Tim", "Alice", "Dilbert"); $ages = array(34, 36, 37); $t = new DTTemplate("table.html"); $t->set("names", $names); $t->set("ages", $ages); $t->send(); and your template (table.html) could look like: {:each:names} {names}{ages+} {:end} The layer above this, the Page Manager, supports the lists of variable hashes you talked about, so that you can give it a big associative array instead of doing a series of set() calls for each variable. - Tim http://www.phptemplates.org - Original Message - From: "scott [gts]" <[EMAIL PROTECTED]> To: "php" <[EMAIL PROTECTED]> Sent: Wednesday, June 20, 2001 5:29 PM Subject: [PHP] Another Template Engine (code) > i wrote a simple classified and hash-enabled template engine > as a sort-of proof of concept -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Another Template Engine (code)
That is awesome, I never got into hash tables, seeing as how the extent of my perl is validating and emailing forms. I am currently porting the template engine to a class, so I can overload alot of the options, like check if it is an array being sent to __registerWatch and act accordingly. You have given me a few ideas, and I think I might extend my engine a bit [no hash tables :P] Chris "TunkeyMicket" Watford TunkeyMicket Productions www.tunkeymicket.com BTW: with the $uid system they never collide, just like file handles never collide :) I thought about using a unique id system based off of random numbers, but after a very long IRC argument i just used the empty brackets to add a new member. - Original Message - From: scott [gts] To: php Sent: Wednesday, June 20, 2001 5:29 PM Subject: [PHP] Another Template Engine (code) i wrote a simple classified and hash-enabled template engine as a sort-of proof of concept placeholders in the template are denoted by %{name}% and they're filled with data by the "regvar()" func. $temp->regvar('name', 'value'); 1) class the engine so that you cay have multiple instances of different templates and not worry about them colliding or corrupting each other. example: $temp1 = new template("filename") $temp1->regvar('THIS', 'Some text'); $temp1->tprint(); 2) put support for hashes of values so you dont have to call regvar() for each and every var, you can simply submit a hash to the template and it'll traverse through it example: $assoc_array('name'=>'scott', 'age'=>'99'); $temp1->hash($assoc_array); will properly replace %{name}% and %{age}% with "scott" and "99" Attached files to this email are: template.php - the template class test.template.php - the calling php script test.template.html - a test template put them all in the same dir and call 'test.template.php' to see the test script. -Original Message-From: TunkeyMicket [mailto:[EMAIL PROTECTED]]Sent: Wednesday, June 20, 2001 11:47 AMTo: [EMAIL PROTECTED]Subject: [PHP] Template Engine Since so many of you are asking for help w/ a template engine of some sort I have included the one I use for my mail program. I have not tested it with large amounts of text, but it is able to handle some very large strings. It has its own documentation, and if anyone needs any help setting it up I'd be willing to help. Chris "TunkeyMicket" Watford TunkeyMicket Productions www.tunkeymicket.com Attached: mp_template_engine.php -- PHP General Mailing List (http://www.php.net/)To unsubscribe, e-mail: [EMAIL PROTECTED]For additional commands, e-mail: [EMAIL PROTECTED]To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Another Template Engine (code)
i wrote a simple classified and hash-enabled template engine as a sort-of proof of concept placeholders in the template are denoted by %{name}% and they're filled with data by the "regvar()" func. $temp->regvar('name', 'value'); 1) class the engine so that you cay have multiple instances of different templates and not worry about them colliding or corrupting each other. example: $temp1 = new template("filename") $temp1->regvar('THIS', 'Some text'); $temp1->tprint(); 2) put support for hashes of values so you dont have to call regvar() for each and every var, you can simply submit a hash to the template and it'll traverse through it example: $assoc_array('name'=>'scott', 'age'=>'99'); $temp1->hash($assoc_array); will properly replace %{name}% and %{age}% with "scott" and "99" Attached files to this email are: template.php - the template class test.template.php - the calling php script test.template.html - a test template put them all in the same dir and call 'test.template.php' to see the test script. -Original Message-From: TunkeyMicket [mailto:[EMAIL PROTECTED]]Sent: Wednesday, June 20, 2001 11:47 AMTo: [EMAIL PROTECTED]Subject: [PHP] Template Engine Since so many of you are asking for help w/ a template engine of some sort I have included the one I use for my mail program. I have not tested it with large amounts of text, but it is able to handle some very large strings. It has its own documentation, and if anyone needs any help setting it up I'd be willing to help. Chris "TunkeyMicket" Watford TunkeyMicket Productions www.tunkeymicket.com Attached: mp_template_engine.php template.php test.template.php Sample template file. Hello, my name is %{name}% and i am %{age}% years old And %{another}% thing! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]