Quick Search:
Oracle PL/SQL Code Library
Find Or Post Oracle Jobs
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

// 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";
PRINT $data;
// 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 -->
<div class='myclass'>{|sample_var_1|}</div>
<div class='myclass'>{|testvar|}</div>

Oracle Magazine
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 26 users online    © 2009 psoug.org

Forgot your password?