« Binaries for rarcrack 0.2 on Microsoft Windows | Home | VirtualBox and 16-bit code »
Simple Template Engine – your lightweight templating engine in PHP
By admin | February 2, 2009
The Simple Template Engine is a very lightweight template engine to use in PHP if your webhost does not allow you to run something like Smarty. It is simple, lightweight and fast.
To parse a file:
<?php // include simple template engine include("tpl.class.php"); $tpl = new template(); $tpl->assign(Array('content'=>"Hello World from Simple Template Engine!")); // If you want to display it directly $tpl->display('example.tpl'); // If you want to send it to another function/class for more processing some_function($tpl->parse('example.tpl')); ?>
example.tpl is:
<html><head><title>{content}</title></head><body><h1>{content}</h1></body></html>
If you found this article useful or helpful, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more useful and interesting articles!
If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more useful and interesting articles!
Topics: (X)HTML, PHP | 9 Comments »
March 4th, 2009 at 08:51
Hi!
Very nice template system 😉
I wonder how can I use php code in the template file? Is it possible?
Thanks
March 7th, 2009 at 05:38
@andrew:
Where you would use:
You would use:
(template code)
Test is %number%
(php code)
assign(Array(‘number’=>strval($s)));
$tpl->display(‘template.tpl’);
?>
February 10th, 2022 at 23:35
… [Trackback]
[…] Find More Info here to that Topic: compdigitec.com/labs/2009/02/02/simple-template-engine-your-lightweight-templating-engine-in-php/ […]
February 13th, 2022 at 07:06
… [Trackback]
[…] There you will find 23191 additional Information to that Topic: compdigitec.com/labs/2009/02/02/simple-template-engine-your-lightweight-templating-engine-in-php/ […]
February 14th, 2022 at 11:17
… [Trackback]
[…] Find More here on that Topic: compdigitec.com/labs/2009/02/02/simple-template-engine-your-lightweight-templating-engine-in-php/ […]
February 27th, 2022 at 07:46
… [Trackback]
[…] Read More Information here on that Topic: compdigitec.com/labs/2009/02/02/simple-template-engine-your-lightweight-templating-engine-in-php/ […]
April 14th, 2022 at 09:52
… [Trackback]
[…] There you can find 43979 additional Info on that Topic: compdigitec.com/labs/2009/02/02/simple-template-engine-your-lightweight-templating-engine-in-php/ […]
May 26th, 2022 at 14:32
… [Trackback]
[…] Read More Info here to that Topic: compdigitec.com/labs/2009/02/02/simple-template-engine-your-lightweight-templating-engine-in-php/ […]
June 20th, 2022 at 06:05
… [Trackback]
[…] Here you will find 71521 additional Info on that Topic: compdigitec.com/labs/2009/02/02/simple-template-engine-your-lightweight-templating-engine-in-php/ […]