{"id":69,"date":"2009-02-02T21:30:26","date_gmt":"2009-02-03T01:30:26","guid":{"rendered":"http:\/\/www.compdigitec.com\/labs\/?p=69"},"modified":"2009-09-13T06:47:23","modified_gmt":"2009-09-13T10:47:23","slug":"simple-template-engine-your-lightweight-templating-engine-in-php","status":"publish","type":"post","link":"http:\/\/www.compdigitec.com\/labs\/2009\/02\/02\/simple-template-engine-your-lightweight-templating-engine-in-php\/","title":{"rendered":"Simple Template Engine &#8211; your lightweight templating engine in PHP"},"content":{"rendered":"<p>The <a href=\"http:\/\/www.phpclasses.org\/browse\/package\/3171.html\">Simple Template Engine<\/a> is a very lightweight template engine to use in PHP if your webhost does not allow you to run something like <a rel=\"nofollow\" href=\"http:\/\/smarty.php.net\/\">Smarty<\/a>. It is simple, lightweight and fast.<\/p>\n<p>To parse a file:<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">&lt;?php\r\n\r\n\/\/ include simple template engine\r\ninclude(&quot;tpl.class.php&quot;);\r\n\r\n$tpl = new template();\r\n\r\n$tpl-&gt;assign(Array('content'=&gt;&quot;Hello World from Simple Template Engine!&quot;));\r\n\r\n\/\/ If you want to display it directly\r\n$tpl-&gt;display('example.tpl');\r\n\r\n\/\/ If you want to send it to another function\/class for more processing\r\nsome_function($tpl-&gt;parse('example.tpl'));\r\n\r\n?&gt;<\/pre>\n<p>example.tpl is:<\/p>\n<p>&lt;html&gt;&lt;head&gt;&lt;title&gt;{content}&lt;\/title&gt;&lt;\/head&gt;&lt;body&gt;&lt;h1&gt;{content}&lt;\/h1&gt;&lt;\/body&gt;&lt;\/html&gt;<\/p>\n<p>If you found this article useful or helpful, please help Compdigitec spread the word. Don&#8217;t forget to <a title=\"Subscribe to Compdigitec Labs\" href=\"\/labs\/feed\/\">subscribe to Compdigitec Labs<\/a> for more useful and interesting articles!<\/p>","protected":false},"excerpt":{"rendered":"<p>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: example.tpl is: &lt;html&gt;&lt;head&gt;&lt;title&gt;{content}&lt;\/title&gt;&lt;\/head&gt;&lt;body&gt;&lt;h1&gt;{content}&lt;\/h1&gt;&lt;\/body&gt;&lt;\/html&gt; If you found this article useful or helpful, please help Compdigitec spread the word. Don&#8217;t forget [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[15,5],"tags":[402,864,403,400,223,404,401],"_links":{"self":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts\/69"}],"collection":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/comments?post=69"}],"version-history":[{"count":0,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts\/69\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/media?parent=69"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/categories?post=69"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/tags?post=69"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}