Quick Search:
 
 PHP Code: Simple one-line template engine Jump to:  
Category: >> PHP Code >> Simple one-line template engine  

<< lastnext >>

Snippet Name: Simple one-line template engine

Description: Very slick, very fast one-line template engine. Faster than Smarty. Items to be replaced are surrounded by '{|" and '|}' tags. The template page can be pre-loaded at any time and then run through the template engine. All items surrounded by the '{|" and '|}' tags will be replaces by the corresponding vars in the '$page_vars' array. Javascript may be embedded freely in the page without interfering with the template engine's operation.

Also see:
» Search and Replace On Every Field In E...
» Regular Expressions: REGEXP_REPLACE
» Inline search and replace
» NVL: Replace NULL values
» Parse RSS into array
» Column copy with string replacement
» Replace a NULL with a given value.
» Search and Replace

Comment: (none)

Language: PHP
Highlight Mode: PHP
Last Modified: March 20th, 2010

<?PHP
// sample page that calls the template engine
$page_vars['sample_var_1'] = 'THE PAGE';
$page_vars['sample_var_2'] = 'SOME  DATA';
$page_vars['testvar'] = 'MORE DATA';
 
$template_file = "testpage.tpl";
INCLUDE("renderer.php");
 
PRINT $data;
 
?>
 
 
 
<?PHP
// template engine
IF(COUNT($page_vars) == 0){PRINT "No data passed to render engine.";exit;}
$data = PREG_REPLACE("/\{\|([^\{]{1,100}?)\|\}/e", "\$page_vars['$1']",FILE_GET_CONTENTS($template_file));
 
?>
 
/*
<!-- sample template page -->
<html>
<body>
<hr>
 
<div class='myclass'>{|sample_var_1|}</div>
 
{|sample_var_2|}
 
<div class='myclass'>{|testvar|}</div>
 
</body>
</html>
 
*/


 
   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org