Skip to content

Instantly share code, notes, and snippets.

@hardevine
Last active December 14, 2015 02:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hardevine/5011318 to your computer and use it in GitHub Desktop.
Save hardevine/5011318 to your computer and use it in GitHub Desktop.
simple templates loader
<?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