Small & fast php template engine
This project have been archived, the new one is Here, using Composer.
PHP 7.0 or newer
- Support pure html as template
 - Support CSS, JS file cache
 - Support CSS model cache
 - Auto minify CSS cache
 - Cache lifetime
 
Now you can choose saving version of template file to local or database
Save to local
//Template setting
$options = array(
    'template_dir' => 'template',
    'css_dir' => 'static/css/', //Set css file's cache
    'js_dir' => 'static/js/', //Set js file's cache
    'static_dir' => 'static/', //Set static file's directory
    'auto_update' => true, //Set 'false' to turn off auto update template
    'cache_lifetime' => 0, //Set cache file's lifetime (minute)
    'cache_db' => false //Set 'false' to save cache version at local directory
);Save to database
//Connect to Database
$connectdb = new mysqli('localhost', 'root', 'root', 'template');
//Template setting
$options = array(
    'template_dir' => 'template',
    'css_dir' => 'static/css/', //Set css file's cache
    'js_dir' => 'static/js/', //Set js file's cache
    'static_dir' => 'static/', //Set static file's directory
    'auto_update' => true, //Set 'false' to turn off auto update template
    'cache_lifetime' => 0, //Set cache file's lifetime (minute)
    'cache_db' => $connectdb //Give connection variable to save cache version into database
);Cache specific part of CSS
html
<link href="{loadcss common.css index}" rel="stylesheet" type="text/css">You can use variable as specific part
<!--{eval $current_page = 'index'}-->
<link href="{loadcss model.css $current_page}" rel="stylesheet" type="text/css">CSS
/*[index]*/
.header {
    display: block;
}
.link {
    color: blue;
}
/*[/index]*/Output: HTML
<link href="cache/model_index.css?v=Ad0Dwf8" rel="stylesheet" type="text/css">cache/model_index.css
/* index */
.header{display:block}.link{color:blue}
/* END index */Also, with array
<!--{eval $current_page = array('index','test')}-->
<link href="{loadcss model.css $current_page}" rel="stylesheet" type="text/css">CSS
/*[index]*/
.header {
    display: block;
}
.link {
    color: blue;
}
/*[/index]*/
/*[test]*/
.header {
    display: inline-block;
}
.link {
    color: red;
}
/*[/test]*/Output: HTML
<link href="cache/model_MULTIPLE.css?v=Ad0Dwf8" rel="stylesheet" type="text/css">cache/model_MULTIPLE.css
/* index */
.header{display:block}.link{color:blue}
/* END index */
/* test */
.header{display:inline-block}.link{color:red}
/* END test */Directly cache CSS file
html
<link href="{loadcss common.css}" rel="stylesheet" type="text/css">Output:
<link href="static/css/common.css?v=Ad0Dwf8" rel="stylesheet" type="text/css">html
<script src="{loadjs jquery.min.js}" type="text/javascript"></script>Output:
<script src="static/js/jquery.min.js?v=B22PE8W" type="text/javascript"></script>html
<img src="{static img/logo.png}" alt="logo">Output:
<img src="static/img/logo.png" alt="logo">html
<span>{$value}</span>PHP
<span><?php echo $value; ?></span>Note: don't put any php script into
blocktag
html
<!--{block test}-->
<span>html content</span>
<!--{/block}-->PHP
<?php
$test = <<<EOF
<span>html content</span>
EOF;
?>html
<!--{if expr1}-->
    statement1
<!--{elseif expr2}-->
    statement2
<!--{else}-->
    statement3
<!--{/if}-->PHP
<?php if(expr1) { ?>
    statement1
<?php } elseif(expr2) { ?>
    statement2
<?php } else { ?>
    statement3
<?php } ?>html
<!--{loop $array $value}-->
    <span>username</span>
<!--{/loop}-->PHP
<?php foreach($array as $value) {?>
    <span>username</span>
<?php } ?>html
<!--{loop $array $key $value}-->
    <span>{$key} = {$value}</span>
<!--{/loop}-->PHP
<?php foreach($array as $key => $value) {?>
    <span><?php echo $key; ?> = <?php echo $value; ?></span>
<?php } ?>html
<!--{eval $value = 1+2}-->
<span>{$value}</span>PHP
<?php eval $value = 1+2;?>
<span><?php echo $value; ?></span>html
<!--{PRESERVE}-->
<span>html content</span>
<!--{/PRESERVE}-->
/*{PRESERVE}*/
<script>
const value = 1+2;
document.querySelector('span').innerHTML = `Value: ${value}`;
</script>
/*{/PRESERVE}*/PHP
<span>html content</span>
<script>
const value = 1+2;
document.querySelector('span').innerHTML = `Value: ${value}`;
</script>Template regex function & cache method with big thanks to TXGZ