Created
December 19, 2011 14:10
-
-
Save dandehavilland/1497404 to your computer and use it in GitHub Desktop.
render PHP template inline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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