RE: [PHP] Easy Template class?
| From: | Lawrence dot Sheed at dfait-maeci dot gc dot ca | Date: | Mon, 13 Nov 2000 03:05:48 +0000 |
| Subject: | RE: [PHP] Easy Template class? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-24903@lists.php.net to get a copy of this message | ||
I do something along the lines of the code below.
template_class.php
<?php
function LoadFile ($filename){
if (file_exists($filename)) {
$fd = fopen( $filename, "r" );
$contents = fread( $fd, filesize( $filename ) );
//fclose( $fd );
}
else {
$contents = "<br><font color=red>Unable to
open:$filename</font></br>";
}
return ($contents);
}
function ParseFile (&$contents,$item,$newvalue) {
$contents = ereg_replace ($item,$newvalue,$contents);
}
?>
Example parser
<?php
include "template_class.php";
$contents = LoadFile ("example.html");
ParseFile ($contents, "{TITLE}", "my brand new title here");
print ($contents);
?>
example.html
<html>
<title>
{TITLE}
</title>
stuff here...
{MENU}
</html>
To embed one file within another, you can do:
example2.html
<menu stuff here>
...
</menu stuff>
2nd_example.php
<?php
include "template_class.php";
$contents = LoadFile ("example.html");
$menu = LoadFile ("example2.html");
ParseFile ($contents, "{TITLE}", "my brand new title here");
ParseFile ($contents, "{MENU}",$menu);
print ($contents);
?>
Simple hey!
Cheers,
Lawrence.
-----Original Message-----
From: Roy Nasser [mailto:roy@vem.ca]
Sent: November 13, 2000 11:12 AM
To: Php (E-mail)
Subject: RE: [PHP] Easy Template class?
I think i moaned a little bit too much in my last e-mail but didnt provide
any suggestions for what i wanted... Here goes:
I think that Instead of having a set_var with jsut the name of the template
variable and the value, it should be something like:
Set_Var("SomeVariable",$SomeValue,"MyTemplateA");
Set_Var("SomeDifferentVariable",$SomeOtherValue,"MyTemplateB");
And then something like:
Embed_Template("Menu","MyTemplateA","MyTemplateB");
What this would do is:
#1: {SomeVariable} in MyTemplateA would become $SomeValue
#2: {SomeDifferentVariable} in MyTemplateB would become $SomeOtherValue
#3: {Menu} in MyTemplateA would become MyTemplateB with everything that has
been done to it (Such as the {SomeVariable})
Thanks again....
Roy Nasser
CTO
Vem Cá Servicos de Internet S/C Ltda.
Av. Paulista 2421 14* Andar
São Paulo SP Brasil
55 11 3347 3456 / 9953 8853 - cel
www.jarbas.com.br
roy@vem.ca
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net