https://github.com/carry0987/php-template-engine
Small & fast php template engine
https://github.com/carry0987/php-template-engine
html mysqli php php-template-engine template-engine
Last synced: 6 months ago
JSON representation
Small & fast php template engine
- Host: GitHub
- URL: https://github.com/carry0987/php-template-engine
- Owner: carry0987
- License: mit
- Created: 2018-05-24T04:37:16.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-10-22T10:46:26.000Z (over 2 years ago)
- Last Synced: 2023-10-22T11:40:08.023Z (over 2 years ago)
- Topics: html, mysqli, php, php-template-engine, template-engine
- Language: PHP
- Homepage:
- Size: 310 KB
- Stars: 9
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Template-Engine
Small & fast php template engine
## Note
This project have been **archived**, the new one is [Here](Https://github.com/carry0987/TemplateEngine), using `Composer`.
## Requires
PHP 7.0 or newer
## Features
- Support pure html as template
- Support CSS, JS file cache
- Support CSS model cache
- Auto minify CSS cache
- Cache lifetime
## Usage
Now you can choose saving version of template file to local or database
Save to local
```php
//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
```php
//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 CSS & JS File
#### CSS Cache
**Cache specific part of CSS**
html
```html
```
You can use variable as `specific part`
```html
```
CSS
```css
/*[index]*/
.header {
display: block;
}
.link {
color: blue;
}
/*[/index]*/
```
Output:
HTML
```html
```
`cache/model_index.css`
```css
/* index */
.header{display:block}.link{color:blue}
/* END index */
```
Also, with **`array`**
```html
```
CSS
```css
/*[index]*/
.header {
display: block;
}
.link {
color: blue;
}
/*[/index]*/
/*[test]*/
.header {
display: inline-block;
}
.link {
color: red;
}
/*[/test]*/
```
Output:
HTML
```html
```
`cache/model_MULTIPLE.css`
```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
```html
```
Output:
```html
```
#### JS Cache
html
```html
```
Output:
```html
```
#### Static File
html
```html
```
Output:
```html
```
## Functions
#### **`echo`** function
html
```html
{$value}
```
PHP
```php
```
#### **`assign variable`** function
>Note: don't put any php script into **`block`** tag
html
```html
html content
```
PHP
```php
html content
EOF;
?>
```
#### **`if`** function
html
```html
statement1
statement2
statement3
```
PHP
```php
statement1
statement2
statement3
```
#### **`loop`** function (without key)
html
```html
username
```
PHP
```php
username
```
#### **`loop`** function (with key)
html
```html
{$key} = {$value}
```
PHP
```php
$value) {?>
=
```
#### **`eval`** function
html
```html
{$value}
```
PHP
```php
```
## **`PRESERVE`** mark
html
```html
html content
/*{PRESERVE}*/
const value = 1+2;
document.querySelector('span').innerHTML = `Value: ${value}`;
/*{/PRESERVE}*/
```
PHP
```php
html content
const value = 1+2;
document.querySelector('span').innerHTML = `Value: ${value}`;
```
## Thanks
Template **regex function** & **cache method** with big thanks to **[TXGZ](https://github.com/txgz999)**