public
Last active

simple templates loader

  • Download Gist
tpls-loader.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
<?php
 
$tplsArr = array();
$filesArr = glob( 'js/app/tpls/*' );
 
// recursive loop through folder js/app/tpls to load all tpls
function loop($files,$tpls_arr) {
 
foreach ( $files as $key => $file ) {
if(is_dir($file)) {
$subDirFiles = glob($file."/*");
$tpls_arr = loop($subDirFiles,$tpls_arr);
 
} else {
preg_match( '/tpls\/(.*)\.handlebars$/', $file, $match );
$fn = $match[1];
if($fn != "") $tpls_arr[$fn] = file_get_contents($file);
 
}
}
 
return ($tpls_arr);
 
}
 
$tplsArr = loop($filesArr,array());
 
?>
 
<script type="text/javascript">
window.Tpls = <? echo json_encode($tplsArr,JSON_HEX_TAG); ?>;
 
</script>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.