Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Michal Tatarynowicz http://notnotes.com/

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Simplest possible PHP templating engine

// This code takes a template name and an array of variables
// and parses them with a file
//
// Example:
// print template('hello', array('who'=>'world'));
//
// Template (/templates/hello.html)
// Hello <?=$who?>!
//
// Outputs:
// Hello world!

   1  
   2  define('DIR_TEMPLATES', dirname(__FILE__).'/templates');
   3  
   4  function template($__name__, $__data__=array()) {
   5  	extract($__data__);
   6  	ob_start();
   7  	require(DIR_TEMPLATES.'/'.$__name__.'.html');
   8  	return ob_get_clean();
   9  }
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS