Skip to content

Instantly share code, notes, and snippets.

@jervert
Created December 29, 2013 18:57
Show Gist options
  • Save jervert/8173563 to your computer and use it in GitHub Desktop.
Save jervert/8173563 to your computer and use it in GitHub Desktop.
Execute PHP template from file and return the result as a string
<?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