Created
December 29, 2013 18:57
-
-
Save jervert/8173563 to your computer and use it in GitHub Desktop.
Execute PHP template from file and return the result as a string
This file contains 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 | |
/* | |
* SliceTemplate - Execute PHP template from file and return the result as a string | |
* | |
* Copyright (c) 2013 Antonio Rodríguez Ruiz | |
* | |
* Licensed under the MIT license: | |
* http://www.opensource.org/licenses/mit-license.php | |
* | |
* Project home: | |
* http://outbook.es | |
* | |
* Version: 1.0.0 | |
* | |
* Params: | |
* - tmpl_file: PHP file which contains the template. String. Mandatory | |
* - vars: array with variables. Array. Optional | |
* | |
* sliceTemplate('template.php', array('variable1' => 'value1', 'variable2' => 'value2')) | |
* | |
* | |
*/ | |
function sliceTemplate($tmpl, $vars = array()) { | |
extract($vars); | |
ob_start(); | |
require($tmpl); | |
$parsedTemplate = ob_get_contents(); | |
ob_end_clean(); | |
return $parsedTemplate; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment