Skip to content

Instantly share code, notes, and snippets.

@dandehavilland
Created December 19, 2011 14:10
Show Gist options
  • Save dandehavilland/1497404 to your computer and use it in GitHub Desktop.
Save dandehavilland/1497404 to your computer and use it in GitHub Desktop.
render PHP template inline
<?php
function render_template($filename, $locals=array()) {
explode($locals);
ob_start();
include($filename);
return ob_get_clean();
}
// template.html.php
//
// <div>
// <h1><?=$title?></h1>
// <p><?$=$content?></p>
// </div>
//
//
// func call
//
// $rendered = render_template("template.html.php", array('title' = "Something", 'content' => "Lorem ipsum...."));
//
//
// => $rendered
//
// <div>
// <h1>Something</h1>
// <p>Lorem ipsum....</p>
// </div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment