Last active
December 14, 2015 02:09
-
-
Save hardevine/5011318 to your computer and use it in GitHub Desktop.
simple templates loader
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 | |
$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> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment