Another Template Engine (code)
| From: | scott [gts] | Date: | Wed, 20 Jun 2001 21:29:02 +0000 |
| Subject: | Another Template Engine (code) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-54615@lists.php.net to get a copy of this message | ||
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:tunkeymicket@tunkeymicket.com]
Sent: Wednesday, June 20, 2001 11:47 AM
To: php-general@lists.php.net
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
Attachment: [application/octet-stream] template.php
Attachment: [application/octet-stream] test.template.php
Attachment: [text/html] test.template.html
Attachment: [application/octet-stream] template.php
Attachment: [application/octet-stream] test.template.php
Attachment: [text/html] test.template.html