Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 PHP Code: Simple one-line template engine Jump to:  
Category: >> PHP Code >> Simple one-line template engine Bookmark and Share

<< 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>
 
*/


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 147 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?